-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhoneDecoderBasic.java
More file actions
22 lines (19 loc) · 973 Bytes
/
PhoneDecoderBasic.java
File metadata and controls
22 lines (19 loc) · 973 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public class PhoneDecoderBasic {
public static void main(String[] args) {
String input = "800888TEST";
String output = "";
for (int i = 0; i < input.length(); i++) {
char ch = input.charAt(i);
if (ch == 'A' || ch == 'B' || ch == 'C') output += '2';
else if (ch == 'D' || ch == 'E' || ch == 'F') output += '3';
else if (ch == 'G' || ch == 'H' || ch == 'I') output += '4';
else if (ch == 'J' || ch == 'K' || ch == 'L') output += '5';
else if (ch == 'M' || ch == 'N' || ch == 'O') output += '6';
else if (ch == 'P' || ch == 'Q' || ch == 'R' || ch == 'S') output += '7';
else if (ch == 'T' || ch == 'U' || ch == 'V') output += '8';
else if (ch == 'W' || ch == 'X' || ch == 'Y' || ch == 'Z') output += '9';
else output += ch;
}
System.out.println("Converted number: " + output);
}
}