The CountLetters application is limited to counting letters in a single word. Modify the CountLetters application to count the letters in an entire phrase, which contains spaces. Care must be taken to ignore the spaces and any other non alphabetic character found in the phrase. Be sure to change comments and variable names appropriately so that the reader of the application code understands that the letters in a phrase are counted.


import java.util.Scanner;

public class CountLetters {

public static void main(String[] args) {
final int LOW = 'A'; //smallest possible value
final int HIGH = 'Z'; //highest possible value
int[] letterCounts = new int[HIGH - LOW + 1];
Scanner input = new Scanner(System.in);
String phrase;
char[] wordLetters;
int offset; //array index

/* prompt user for a phrase */
System.out.print("Enter a phrase: ");
phrase = input.nextLine();
input.close();

/* convert word to char array and count letter occurrences */
phrase = phrase.toUpperCase();
wordLetters = phrase.toCharArray();
for (int letter = 0; letter < wordLetters.length; letter++) {
offset = wordLetters[letter] - LOW;
letterCounts[offset] += 1;
}

/* show letter occurrences */
for (int i = LOW; i <= HIGH; i++) {
System.out.println((char)i + ": " + letterCounts[i - LOW]);
}
}

}