Results 1 to 3 of 3

Thread: hi all

  1. #1
    Shimless12 is offline Member
    Join Date
    Jul 2011
    Posts
    12
    Rep Power
    0

    Default hi all

    hello well im trying to count the frequency of same length words by using this code within a applet:
    Java Code:
    public void actionPerformed (ActionEvent e){
    if(e.getSource() == analyzeButton){ // Analyse Button
    	String paragraph;
    
    	paragraph = textEntry.getText();
    	    HashMap <Integer, Integer> frequencyTable = new HashMap<Integer, Integer>();
    	   
    	    for (int i = 0; i < paragraph.length(); i++)
    	    {
    	      if (!frequencyTable.containsKey(paragraph.length()))
    	        frequencyTable.put(paragraph.length(), 1);
    	      else
    	      {
    	        Integer count = frequencyTable.get(paragraph.length()) + 1;
    	        frequencyTable.put(paragraph.length(), count);
    	        
    	      }
    	     
    	    }
    	
         	wordlength.setText("analyzed text: " + frequencyTable);
    and it comes out with {10=10} when i enter "i am a man"
    when it should come out 2, 1, 1
    help

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,562
    Rep Power
    25

    Default

    What do you intend to be saved in the HashMap?

    Where does this code display: {10=10} ?

    Add some println statements to show the values of the variables as they change and are set.

  3. #3
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    You should probably split the paragraph into words. Right now you are not really doing anything useful. You should definitely re examine the logic of your code.

Posting Permissions

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