public class CountLetters { public static void main(String[] arg) { int[] lower = new int[26]; int[] upper = new int[26]; for(int i = 0; i < 26; i++) lower[i] = upper[i] = 0; Scanner input = new Scanner(System.in); System.out.print("Enter the string: "); while(input.hasNext()) { String temp = input.next(); for (int i = 0; i < temp.length(); i++) { char c = temp.charAt(i); if (Character.isUpperCase(c)) upper[(int) c - 65]++; if (Character.isLowerCase(c)) lower[(int) c - 97]++; } input.next(); } System.out.print("a is " + lower[0]); System.out.print("A is " + upper[0]); } }
See the following link:
input.next();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)