题目:请输入星期几的第一个字母,判断一下是星期几,如果第一个字母一样,则继续,
*反之,判断第二个字母,知道可以判断是星期几
1 public class _026Weekday { 2 3 public static void main(String[] args) { 4 while (true) { 5 weekday(); 6 } 7 } 8 9 private static void weekday() { 10 System.out.println("请输入星期的第一个大写字母 :"); 11 char ch = getchar(); 12 switch (ch) { 13 case 'M': 14 System.out.println("Monday"); 15 break; 16 case 'W': 17 System.out.println("Wednesday"); 18 break; 19 case 'F': 20 System.out.println("Friday"); 21 break; 22 case 'T': { 23 System.out.println("请输入星期的第二个字母:"); 24 char ch2 = getchar(); 25 if (ch2 == 'U') { 26 System.out.println("Tuesday"); 27 } else if (ch2 == 'H') { 28 System.out.println("Thursday"); 29 } else { 30 System.out.println("不是星期的写法"); 31 } 32 } 33 ; 34 break; 35 case 'S': { 36 System.out.println("请输入星期的第二个字母:"); 37 char ch2 = getchar(); 38 if (ch2 == 'U') { 39 System.out.println("Sunday"); 40 } else if (ch2 == 'A') { 41 System.out.println("Saturday"); 42 } else { 43 System.out.println("不是星期的写法"); 44 } 45 } 46 ; 47 break; 48 49 default: 50 System.out.println("不是星期的写法"); 51 ; 52 } 53 } 54 55 private static char getchar() { 56 Scanner scanner = new Scanner(System.in); 57 String s = scanner.nextLine(); 58 char ch = s.charAt(0); 59 if (ch < 'A' || ch > 'Z') { 60 System.out.println("输入错误,请重新输入"); 61 ch = getchar(); 62 } 63 return ch; 64 } 65 66 }