import java.util.*; public class LetCount { public static final int NUMCHARS = 26 + 1; //You define public static int addr(char ch) { return (int) ch - (int) 'A' + 1; } public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); // for reading input int[] count = new int [NUMCHARS]; int curIndex = 0; int max = 0; System.out.println("Enter text to be read"); while (keyboard.hasNext()) { String str1 = keyboard.nextLine().toUpperCase(); char ch = str1.charAt(curIndex); for(curIndex = 0; curIndex < str1.length(); curIndex++) { ch = str1.charAt(curIndex); if (ch >= 'A' && ch <= 'Z') { addr(ch); count[ch - 'A']++; } for (int i = 0; i < 26; ++i) { int highest; highest = count[i]; System.out.printf(" %c ", i + 'A'); System.out.println("occurred " + count[i] + " times"); if (highest >= max) { if (highest > max) { max = highest; } } } System.out.println(max); } } } }
Other than maybe too many } why does this print out a statment for every letter?
Im trying to take it and print out the count for each letter and say the highest and lowest of the counts