Created
November 9, 2012 22:39
-
-
Save jimternet/4048794 to your computer and use it in GitHub Desktop.
Phone number problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.*; | |
| import java.lang.*; | |
| import java.util.Map; | |
| public class PhoneNumberSolver{ | |
| //3 numbers just for examples sake so far | |
| private static Integer[] phoneNumber = new Integer[]{new Integer(3) , new Integer(5), new Integer(5)}; | |
| /* | |
| String{]{"d","e","f"}) | |
| String{]{"j","k","l"} | |
| String{]{"j","k","l"} | |
| djj | |
| djk | |
| djl | |
| dkj | |
| dkk | |
| dkl | |
| dlj | |
| dlk | |
| dll | |
| ejj | |
| ejk | |
| ejl | |
| ekj | |
| ekk | |
| ekl | |
| elj | |
| elk | |
| ell | |
| fjj | |
| fjk | |
| fjl | |
| fkj | |
| fkk | |
| fkl | |
| flj | |
| flk | |
| fll | |
| */ | |
| private static final Map <Integer, String[]> alphaNumericMap = new HashMap<Integer, String[]>(); | |
| private static List<String> alphaNumericListOfPossibilites = new ArrayList<String>(); | |
| public static void main(String [] args){ | |
| initMap(); | |
| //3 | |
| String [] optionsForPositionZero = alphaNumericMap.get(phoneNumber[0]); | |
| String [] optionsForPositionOne = alphaNumericMap.get(phoneNumber[1]); | |
| String [] optionsForPositionTwo = alphaNumericMap.get(phoneNumber[2]); | |
| for (int zeroIterator=0;zeroIterator<optionsForPositionZero.length;zeroIterator++ ){ | |
| for (int oneIterator=0;oneIterator<optionsForPositionZero.length;oneIterator++ ){ | |
| for (int twoIterator=0;twoIterator<optionsForPositionTwo.length;twoIterator++ ){ | |
| alphaNumericListOfPossibilites.add(optionsForPositionZero[zeroIterator] | |
| + optionsForPositionOne[oneIterator] | |
| + optionsForPositionTwo[twoIterator]); | |
| }//endTwoIterator | |
| }//end oneIterator | |
| } //end zeroIterator | |
| Object[] alphaNumericArrayOfPossibilites = alphaNumericListOfPossibilites.toArray(); | |
| System.out.println(Arrays.toString(alphaNumericArrayOfPossibilites)); | |
| } //end main | |
| private static void initMap (){ | |
| alphaNumericMap.put(new Integer(1),new String[]{"1"}); | |
| alphaNumericMap.put(new Integer(2),new String[]{"a","b","c"}); | |
| alphaNumericMap.put(new Integer(3),new String[]{"d","e","f"}); | |
| alphaNumericMap.put(new Integer(4),new String[]{"g","h","i"}); | |
| alphaNumericMap.put(new Integer(5),new String[]{"j","k","l"}); | |
| alphaNumericMap.put(new Integer(6),new String[]{"m","n","o"}); | |
| alphaNumericMap.put(new Integer(7),new String[]{"p","q","r","s"}); | |
| alphaNumericMap.put(new Integer(8),new String[]{"t","u","v"}); | |
| alphaNumericMap.put(new Integer(9),new String[]{"w","x","y","z"}); | |
| alphaNumericMap.put(new Integer(0),new String[]{"0"}); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment