1StringBuilder phone = new StringBuilder();
2for (int i = 0; i < number.length(); i++){
3 if (Character.isLetter(number.charAt(i))){
4 phone.append(getNumber(Character.toUpperCase(number.charAt(i))));
5 }else{
6 phone.append(number.charAt(i));
7 }
8}
9
10System.out.println("Your number is " + phone.toString());
1 public static void main(String[] args){
2 Scanner input = new Scanner(System.in);
3
4 System.out.print("Enter phone number: ");
5 String number = input.nextLine();
6 String phone ="";
7
8 for (int i = 0; i < number.length(); i++){
9 if (Character.isLetter(number.charAt(i)))
10 phone = getNumber(Character.toUpperCase(number.charAt(i)));
11 else
12 number.charAt(i);
13 }
14 System.out.println("Your number is " + phone);
15 }
16
17
18public static int getNumber(char uppercaseLetter){
19 if (uppercaseLetter >= 'W' && uppercaseLetter <= 'Z')
20 return 9;
21 else if (uppercaseLetter >= 'T' && uppercaseLetter < 'W')
22 return 8;
23 else if (uppercaseLetter >= 'P' && uppercaseLetter < 'T')
24 return 7;
25 else if (uppercaseLetter >= 'M' && uppercaseLetter < 'P')
26 return 6;
27 else if (uppercaseLetter >= 'J' && uppercaseLetter < 'M')
28 return 5;
29 else if (uppercaseLetter >= 'G' && uppercaseLetter < 'J')
30 return 4;
31 else if (uppercaseLetter >= 'D' && uppercaseLetter < 'G')
32 return 3;
33 else
34 return 2;
35 }
36}