Hi, So I'm trying to write a program in which the user enters a word, then the program displays each letter of the alphabet and how many times each letter is used in that word.
Ex. "Testing" A-0 B-0 .... S-1 T-2
Like that
However, I don't know whats wrong with the code and how to fix it?
Any help is appreciated
import java.lang.String; public class Words { public static void main(String[]args) { String words = new String(); words = Input.getString("Please enter a statement"); int[]total = totalLetters(words.toLowerCase()); for (int i=0; i < total.length; i++) { if (total[i]!=0) System.out.println("Letter " + (char)('a' + i) + " count = " + total[i]); } } public static int[]totalLetters(String words) { int[]total = new int[26]; for (int i=0; i < words.length(); i++) { if (Character.isLetter(words.charAt(i))) { total[words.charAt(i) - 'a']++ ; } } return total; } }