Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- import java.util.Scanner;
- public class Q2v2 {
- private static Scanner kb;
- private static String input;
- private static HashMap<Character, String> maps;
- public static void printCombos()
- {
- printCombosRecurse("", 0);
- }
- public static void printCombosRecurse(String pass, int index)
- {
- if(pass.length() == input.length())
- System.out.println(pass);
- else
- {
- for(int x = 0; x < maps.get(input.charAt(index)).length(); x++)
- {
- printCombosRecurse(pass + maps.get(input.charAt(index)).charAt(x), index +1 );
- }
- }
- }
- public static void main(String[] args)
- {
- maps = new HashMap<Character, String>();
- 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");
- System.out.println("Enter a number: ");
- input = kb.nextLine();
- printCombos();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement