解题思路:用switch区分字母做判断
代码:public class Main13 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.println("请输入第一个字母:");
String a = input.next();
switch (a) {
case "m":
System.out.println("Monday");
break;
case "t":
System.out.println("请输入第二个字母:");
String b = input.next();
if(b.equals("u")){
System.out.println("Tuesday");
}else if(b.equals("h")){
System.out.println("Thursday");
}else{
System.out.println("输入有错误");
}
break;
case "w":
System.out.println("Wednesday");
break;
case "f":
System.out.println("Friday");
break;
case "s":
String c = input.next();
if(c.equals("u")){
System.out.println("Sunday");
}else if(c.equals("a")){
System.out.println("Saturday");
}else{
System.out.println("输入有错误");
}
break;
default:
System.out.println("输入有错误");
break;
}
}
}