请输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续 判断第二个字母。
import java.util.Scanner;
public class XingZi {
Scanner s = new Scanner(System.in);
public static void main(String[] args) {
XingZi tw = new XingZi();
char ch = tw.getChar();
switch (ch) {
case 'M':
System.out.println("Monday");
break;
case 'W':
System.out.println("Wednesday");
break;
case 'F':
System.out.println("Friday");
break;
case 'T': {
System.out.println("please input the second letter!");
char ch2 = tw.getChar();
if (ch2 == 'U') {
System.out.println("Tuesday");
} else if (ch2 == 'H') {
System.out.println("Thursday");
}
}
;
break;
case 'S': {
System.out.println("please input the scecond letter!");
char ch2 = tw.getChar();
if (ch2 == 'U') {
System.out.println("Sunday");
} else if (ch2 == 'A') {
System.out.println("Saturday");
}
}
;
break;
}
}
public char getChar() {
String str = s.nextLine();
char ch = str.charAt(0);
if (ch < 'A' || ch > 'Z') {
System.out.println("Input error, please input a capital letter");
getChar();
}
return ch;
}
}