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++;
}
}
}