import java.util.HashMap; import java.util.Scanner; public class Q3 { private static Scanner kb; private static String input; private static HashMap maps; private static int counter = 0; public static void printCombos() { printCombosRecurse("", 0); } public static void step(String pass, int x, int length, int index) { if(x < length) { printCombosRecurse(pass + maps.get(input.charAt(index)).charAt(x), index + 1 ); step(pass, x+1, length, index); } } public static void printCombosRecurse(String pass, int index) { if(pass.length() == input.length()) { System.out.println(pass); counter++; } else { step(pass, 0, maps.get(input.charAt(index)).length(), index); } } public static void main(String[] args) { maps = new HashMap(); kb = new Scanner(System.in); maps.put('0', "0"); maps.put('1', "1"); maps.put('2', "ABC"); maps.put('3', "DEF"); maps.put('4', "GHI"); maps.put('5', "JKL"); maps.put('6', "MNO"); maps.put('7', "PQRS"); maps.put('8', "TUV"); maps.put('9', "WXYZ"); do { System.out.println("Enter a phone number (numbers only). Type \"exit\" to end."); input = kb.nextLine(); if(!input.equals("exit")) { printCombos(); System.out.println(counter + " option(s) are available"); counter = 0; } }while(!input.equals("exit")); System.out.println("Bye!"); } }