-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlphaTeleNumberTranslator.java
More file actions
60 lines (53 loc) · 1.93 KB
/
AlphaTeleNumberTranslator.java
File metadata and controls
60 lines (53 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import java.util.Scanner;
public class AlphaTeleNumberTranslator {
public static void main(String[] args) {
translateNumber(new Scanner(System.in));
}
private static void translateNumber(Scanner kb) {
String result = "";
System.out.println("enter the phrase to be translated");
String translate = kb.nextLine().toLowerCase();
for(int i = 0; i < translate.length(); i++) {
if(translate.charAt(i) == 'a' || translate.charAt(i) == 'b' || translate.charAt(i) == 'c') {
result = result + "2";
}
else if(translate.charAt(i) == 'd' || translate.charAt(i) == 'e' || translate.charAt(i) == 'f') {
result = result + "3";
}
else if(translate.charAt(i) == 'g' || translate.charAt(i) == 'h' || translate.charAt(i) == 'i') {
result = result + "4";
}
else if(translate.charAt(i) == 'j' || translate.charAt(i) == 'k' || translate.charAt(i) == 'l') {
result = result + "5";
}
else if(translate.charAt(i) == 'm' || translate.charAt(i) == 'n' || translate.charAt(i) == 'o') {
result = result + "6";
}
else if(translate.charAt(i) == 'p' || translate.charAt(i) == 'q' || translate.charAt(i) == 'r' || translate.charAt(i) == 's') {
result = result + "7";
}
else if(translate.charAt(i) == 't' || translate.charAt(i) == 'u' || translate.charAt(i) == 'v') {
result = result + "8";
}
else if(translate.charAt(i) == 'w' || translate.charAt(i) == 'x' || translate.charAt(i) == 'y' || translate.charAt(i) == 'z') {
result = result + "9";
}
else {
result = result + translate.charAt(i);
}
}
// pretty-print result
for(int i = 0; i < 3; i++) {
System.out.print(result.charAt(i));
}
System.out.print("-");
for(int i = 3; i < 6; i++) {
System.out.print(result.charAt(i));
}
System.out.print("-");
for(int i = 6; i < result.length(); i++) {
System.out.print(result.charAt(i));
}
System.out.println();
}
}