Results 1 to 3 of 3
  1. #1
    avaiblas is offline Member
    Join Date
    Dec 2010
    Posts
    1
    Rep Power
    0

    Default Need help please with coding

    Hello sorry for my bad english but i need your help. This is the code :

    Java Code:
    public class TekstoTvarkymas {
    	private String[] sakinys = new String[1000];
    	private String pirmasZodis;
    
    	public TekstoTvarkymas(String pavadinimas) {
    		Scanner scan = null;
    		FileInputStream filein = null;
    		try {
    			filein = new FileInputStream(pavadinimas);
    			scan = new Scanner(filein);
    			sakinys = scan.nextLine().trim().split(" ");
    			pirmasZodis = sakinys[0];
    		} catch (IOException ex) {
    			System.out.println("Klaida skaitant faila " + pavadinimas);
    		} finally {
    			if (filein != null)
    				scan.close();
    		}
    	}
    
    	public int pasikartoja() {
    		int kartojasi = 0;
    		for (int i = 0; i < sakinys.length; i++)
    			if (sakinys[i] != null && sakinys[i].equalsIgnoreCase(pirmasZodis))
    				kartojasi++;
    		return kartojasi;
    	}
    
    	public void naikintiPasikartojimus() {
    		for (int i = 1; i < sakinys.length; i++)
    			if (sakinys[i] != null && sakinys[i].equalsIgnoreCase(pirmasZodis))
    				sakinys[i] = null;
    	}
    
    	@Override
    	public String toString() {
    		String s = "";
    		for (String l : sakinys)
    			if (l != null )
    				s += l + " ";
    		return s;
    	}
    }
    I need to change that similar words should be removed not changed to null please help.
    Last edited by Eranga; 12-24-2010 at 01:16 AM. Reason: code tags added

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,889
    Rep Power
    8

    Default

    Read this: How To Ask Questions The Smart Way

    Specifically- what does your code do instead? Do you see Exceptions? Strange behavior? What were you expecting? What have you tried?

    Code tags are your friend.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by avaiblas View Post
    I need to change that similar words should be removed not changed to null please help.
    Can you explain what you mean by this?

Similar Threads

  1. Replies: 4
    Last Post: 10-25-2010, 03:49 PM
  2. Need help coding
    By ace_03 in forum New To Java
    Replies: 2
    Last Post: 11-25-2009, 05:16 PM
  3. Coding help
    By Java_Fanatic in forum New To Java
    Replies: 7
    Last Post: 10-15-2009, 04:37 AM
  4. Better coding
    By tomiu in forum New To Java
    Replies: 1
    Last Post: 04-09-2009, 07:19 PM
  5. coding help
    By accies76 in forum New To Java
    Replies: 5
    Last Post: 11-12-2008, 08:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •