Advertisement
Sinux1

PhonePadRecursive

Dec 1st, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1.  
  2. import java.util.HashMap;
  3. import java.util.Scanner;
  4.  
  5. public class Q2v3 {
  6.     private static Scanner kb;
  7.     private static String input;
  8.     private static HashMap<Character, String> maps;
  9.  
  10.     public static void printCombos()
  11.     {
  12.         printCombosRecurse("", 0);
  13.     }
  14.  
  15.     public static void step(String pass, int x, int length, int index)
  16.     {
  17.         if(x < length)
  18.         {
  19.             printCombosRecurse(pass + maps.get(input.charAt(index)).charAt(x), index + 1 );
  20.             step(pass, x+1, length, index);
  21.         }
  22.     }
  23.     public static void printCombosRecurse(String pass, int index)
  24.     {
  25.         if(pass.length() == input.length())
  26.             System.out.println(pass);
  27.         else
  28.         {
  29.             step(pass, 0, maps.get(input.charAt(index)).length(), index);
  30.  
  31.         }
  32.     }
  33.  
  34.     public static void main(String[] args)
  35.     {
  36.     maps = new HashMap<Character, String>();
  37.     kb = new Scanner(System.in);
  38.     maps.put('0', "0");
  39.     maps.put('1', "1");
  40.     maps.put('2', "ABC");
  41.     maps.put('3', "DEF");
  42.     maps.put('4', "GHI");
  43.     maps.put('5', "JKL");
  44.     maps.put('6', "MNO");
  45.     maps.put('7', "PQRS");
  46.     maps.put('8', "TUV");
  47.     maps.put('9', "WXYZ");
  48.  
  49.     System.out.println("Enter a phone number (numbers only).");
  50.     input = kb.nextLine();
  51.     printCombos();
  52.  
  53.  
  54.  
  55.  
  56.  
  57.     }
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement