Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-06-2009, 11:06 PM
Member
 
Join Date: Oct 2009
Posts: 5
Rep Power: 0
SF163 is on a distinguished road
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++;
}
}

}
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 11-06-2009, 11:15 PM
xcallmejudasx's Avatar
Senior Member
 
Join Date: Oct 2008
Location: Houston, TX & Flint, MI
Posts: 585
Rep Power: 2
xcallmejudasx is on a distinguished road
Send a message via AIM to xcallmejudasx
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-07-2009, 01:04 AM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,326
Rep Power: 8
Fubarable is on a distinguished road
Default
What are your assignment requirements? Also, please edit your code and place in code tags (see my signature below which describes how to do this).
__________________
When posting code, please use code tags so that your code is readable. To do this, place the tag [code] before your block of code and [/code] after your block of code.
How to use Code Tags
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using revision control (RCS) with java itaipee Advanced Java 1 10-29-2009 07:24 PM
I require some urgent help... plzzzz help me Hurricane New To Java 3 08-29-2009 07:49 PM
Require Help with Layout (GridBag) hemanthjava AWT / Swing 2 10-22-2008 02:56 PM
Require some insight! Shaolin JavaServer Pages (JSP) and JSTL 13 07-16-2008 12:36 AM
Java and Eclipse: Adding a build or revision number to application using SVNAnt sal_manilla Eclipse 1 05-16-2008 06:56 PM


All times are GMT +2. The time now is 05:28 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org