Many companies use telephone numbers like 555-GET-Food so the number is easier f
ID: 3621409 • Letter: M
Question
Many companies use telephone numbers like 555-GET-Food so the number is easier for their customers to remember. On a standard telephone, the alphabetic letters are mapped to numbers in the following fashion:A, B, and C = 2
D, E, and F = 3
G, H, and I = 4
J, K, and L = 5
M, N, and O = 6
P, Q, R, and S = 7
T, U, and V = 8
W, X, y, and Z = 9
Write an application that asks the user to enter a 10-character telephone number in the format XXX-XXX-XXXX. The application should display the telephone number with any alphabetic characters that appeared in the original translated to their numeric equivalent. For example, if the user enters 555-GET-FOOD the application should display 555-438-3663.
Explanation / Answer
please rate - thanks
import java.util.*;
public class Telephone
{public static void main(String[] args)
{String number;
int i;
System.out.print("Enter phone number: ");
Scanner in = new Scanner(System.in);
number = in.next();
i=0;
while(i<number.length())
{switch(number.charAt(i))
{case 'A':case 'B':case 'C':
System.out.print("2");
break;
case 'D':case 'E':case 'F':
System.out.print("3");
break;
case 'G':case 'H':case 'I':
System.out.print("4");
break;
case 'J':case 'K':case 'L':
System.out.print("5");
break;
case 'M':case 'N':case 'O':
System.out.print("6");
break;
case 'P':case 'R':case 'S':
System.out.print("7");
break;
case 'T':case 'U':case 'V':
System.out.print("8");
break;
case 'W':case 'X':case 'Y':
System.out.print("9");
break;
default:
System.out.print(number.charAt(i));
}
i++;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.