Java语言程序设计(基础篇)第十版 4.15


public class J4_15 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		java.util.Scanner input = new java.util.Scanner(System.in);
		System.out.print("Enter a letter");
		String letter = input.nextLine();
		
		switch(letter.toUpperCase()) {
		case " ":
			System.out.println("The corresponding number is 0 ");break;
		case "'":
			System.out.println("The corresponding number is 1");break;
		case "A":
		case "B":
		case "C":
			System.out.println("The  corresponding number is 2");break;
		case "D":
		case "E":
		case "F":
			System.out.println("The corresponding number is 3");break;
		case "G":
		case "H":
		case "I":
			System.out.println("The corresponding number is 4");break;
		case "J":
		case "K":
		case "L":
			System.out.println("The corresponding number is 5");break;
		case "M":
		case "N":
		case "O":
			System.out.println("The corresponding number is 6");break;
		case "P":
		case "Q":
		case "R":
		case "S":
			System.out.println("The corresponding number is 7");break;
		case "T":
		case "U":
		case "V":
			System.out.println("The corresponding number is 8");break;
		case "W":
		case "X":
		case "Y":
		case "Z":
			System.out.println("The corresponding number is 9");break;
		default:System.out.println(letter+" is an invalid input");break;
		
		}
		
		
			
		

	}

}

你可能感兴趣的:(java)