Results 1 to 3 of 3
  1. #1
    SF163 is offline Member
    Join Date
    Oct 2009
    Posts
    5
    Rep Power
    0

    Default Require quick program revision please

    When i input the text it doesnt allow me to put spaces. any ideas why??

    import java.util.*;

    public class LetterFreq{
    public static void main(String[] args){
    Letters input1 = new Letters();
    Scanner scan = new Scanner(System.in);
    String t = " ";
    System.out.println("Enter Text Here");
    while(t.length() > 0){
    t = scan.nextLine();
    t = t.toLowerCase();
    input1.countLetters(t);
    }
    input1.printCount();
    }
    }


    public class Letters{
    int[] charCount = new int[26];

    public void countLetters(String input){
    for (int j = 0; j < input.length(); j++){
    int hold = 0;
    hold = input.charAt(j) - 'a';
    if(j >= 0 && j <= 25)
    charCount[hold]++;
    }
    }

    public void printCount(){
    char letter = 'a';
    for (int i = 0; i < 26; i++){
    System.out.println(letter + ": " + charCount[i]);
    letter++;
    }
    }

    }

  2. #2
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default

    You shouldn't need the while look and can just do t = scan.next();
    Liberty has never come from the government.
    Liberty has always come from the subjects of government.
    The history of liberty is the history of resistance.
    The history of liberty is a history of the limitation of governmental power, not the increase of it.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Replies: 4
    Last Post: 10-25-2010, 05:59 AM
  2. Using revision control (RCS) with java
    By itaipee in forum Advanced Java
    Replies: 1
    Last Post: 10-29-2009, 06:24 PM
  3. I require some urgent help... plzzzz help me
    By Hurricane in forum New To Java
    Replies: 3
    Last Post: 08-29-2009, 06:49 PM
  4. Require Help with Layout (GridBag)
    By hemanthjava in forum AWT / Swing
    Replies: 2
    Last Post: 10-22-2008, 01:56 PM
  5. Require some insight!
    By Shaolin in forum JavaServer Pages (JSP) and JSTL
    Replies: 13
    Last Post: 07-15-2008, 11:36 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
  •