Created
March 17, 2017 05:27
-
-
Save M-ZubairAhmed/c18cee12cd464f0933621f4fe6734b37 to your computer and use it in GitHub Desktop.
Calculates number of taps required to type a text in old numpad keyboard phones
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
public class Keypad { | |
public static int presses(String phrase){ | |
int noPresses = 0; | |
for(int i = 0 ; i<phrase.length(); i++){ | |
char aToZ = phrase.toUpperCase().charAt(i); | |
if (aToZ == 'A'||aToZ == 'D'||aToZ == 'G'||aToZ == 'J'||aToZ == 'M'||aToZ == 'P'||aToZ == 'T'||aToZ == 'W'||aToZ == '1'||aToZ == ' '||aToZ == '*'||aToZ == '#'){ | |
noPresses = noPresses + 1; | |
System.out.println(noPresses+" 1 = "+aToZ);} | |
else if (aToZ == 'B'||aToZ == 'E'||aToZ == 'H'||aToZ == 'K'||aToZ == 'N'||aToZ == 'Q'||aToZ == 'U'||aToZ == 'X'||aToZ == '0'){ | |
noPresses = noPresses + 2; | |
System.out.println(noPresses+" 2 = "+aToZ);} | |
else if (aToZ == 'C'||aToZ == 'F'||aToZ == 'I'||aToZ == 'L'||aToZ == 'O'||aToZ == 'R'||aToZ == 'V'||aToZ == 'Y'){ | |
noPresses = noPresses + 3; | |
System.out.println(noPresses+" 3 = "+aToZ);} | |
else if (aToZ == 'S'||aToZ == 'Z'||aToZ == '2'||aToZ == '3'||aToZ == '4'||aToZ == '5'||aToZ == '6'||aToZ == '8'){ | |
noPresses = noPresses + 4; | |
System.out.println(noPresses+" 4 = "+aToZ);} | |
else if (aToZ == '7'||aToZ == '9'){ | |
noPresses = noPresses + 5; | |
System.out.println(noPresses+" 5 = "+aToZ);} | |
else{ | |
noPresses = noPresses + 0; | |
System.out.println(noPresses+" 0 = "+aToZ);} | |
} | |
return noPresses; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
MultiTap-keypad-stroke-calculator
Calculates number of taps required to type a text in old numpad keyboard phone 3x4 numeric as follows.
| | | ABC | | DEF |
| 1 | | 2 | | 3 |
| GHI | | JKL | | MNO |
| 4 | | 5 | | 6 |
|PQRS | | TUV | | WXYZ |
| 7 | | 8 | | 9 |
| | |space | | |
| * | | 0 | | # |
Multi-tap and involved pressing a button repeatedly to cycle through the possible values. To send a following message: "WHERE DO U WANT 2 MEET L8R" one have to do 47 button presses.