题目:
(电话键盘)电话上的国际标准字母/数字映射如下图所示:
编写一个程序,提示用户输入一个字母,然后显示对应的数字。
public static void f4()
{
System.out.print("Enter an uppercase character : ");
String str=input.nextLine();
char ch = Character.toUpperCase(str.charAt(0));
if('A' <= ch && ch <= 'C')
System.out.println(" The corresponding number is 2");
else if( 'D' <= ch && ch <= 'F')
System.out.println(" The corresponding number is 3");
else if( 'G' <= ch && ch <= 'I')
System.out.println(" The corresponding number is 4");
else if( 'J' <= ch && ch <= 'L')
System.out.println(" The corresponding number is 5");
else if( 'M' <= ch && ch <= 'O')
System.out.println(" The corresponding number is 6");
else if( 'P' <= ch && ch <= 'S')
System.out.println(" The corresponding number is 7");
else if( 'T' <= ch && ch <= 'V')
System.out.println(" The corresponding number is 8");
else if( 'W' <= ch && ch <= 'Z')
System.out.println(" The corresponding number is 9");
else
System.out.println(ch+" is an invalid input");
}