I have to complete a project that does the following: Write a program that prompts the user to input a string of words, then counts and displays the number of times each letter in the alphabet appears in the string. It is not necessary to distinguish between uppercase and lowercase letters. Your output should be formatted as follows:
Letter A count = xx
Letter B count = xx
....
Letter Z count = xx
I edited it so it looks like this now. The only issue now is that the uppercase letters are being ignored during the letter count, and I'm not quite sure what the issue is.
public class Assignment9 {
public static void main(String[] sa) {
int letters [] = new int[ 26 ];
String s;
char y;
for ( int x = 0; x < letters.length; x++ )
{
letters[x] = 0;
}
s = Input.getString("Type a phrase with characters only, please.");
s.toLowerCase();
for ( int x = 0; x < s.length(); x++ )
{
y = s.charAt(x);
if ( y >= 'a' && y <= 'z' )
{
letters[ y - 'a' ]++;
}
}
for ( y = 'a'; y <= 'z'; y++ )
{
System.out.println( "Letter " + y + " = " + letters[ y - 'a'] + " ");
}
}
}