面向对象的第一次pta作业第三题:电话键盘字母数字转换
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner letter = new Scanner(System.in); String str; str=letter.nextLine(); String str1=str.toUpperCase(); char s=str1.charAt(0); if(s>'Z'||s<'A') { System.out.print(str.charAt(0)); System.out.print(" is an invalid input"); } else if(s<='C') System.out.print(2); else if(s<='F') System.out.print(3); else if(s<='I') System.out.print(4); else if(s<='L') System.out.print(5); else if(s<='O') System.out.print(6); else if(s<='S') System.out.print(7); else if(s<='V') System.out.print(8); else System.out.print(9); } }
还是有一种在复习c语言的感觉呢~