// Program 84: Telephone Keypad Keystrokes import java.util.*; class KeypadStrokes { static final String[] keys = { "ABC", "DEF", "GHI", "JKL", "MNO", "PQRS", "TUV", "WXYZ" } ; public static void main(String[] args) { Scanner sc = new Scanner(System.in); String word = sc.nextLine().trim().toUpperCase(Locale.ROOT); if (!word.matches("[A-Z]+")) { System.out.println("INVALID ENTRY"); return; } int total = 0; for (char c : word.toCharArray()) { for (String key : keys) { int pos = key.indexOf(c); if (pos >= 0) { total += pos + 1; break; } } } System.out.println("Number of keystrokes = " + total); } }