Advertisement
Sinux1

PhonePadRecursive

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