package XiTi;
import java.util.Scanner;
public class S_C_X {
public static void main(String[] args) {
char S;
Scanner sc = new Scanner(System.in);
System.out.println("請輸入星期值的第一個字母:");
String f = sc.next();
//判斷輸入的字符串長度是否是一個字母
if (f.length() == 1) {
char wF = f.charAt(0); //利用取第一個索引的字符來實現讓Scanner 接收 char 類型輸入
switch (wF) {
case 'm':
case 'M': {
System.out.println("星期一(Monday)");
}
case 'T':
case 't': {
System.out.println("由於星期二(Tuesday)和星期四(Thursday)都是T開頭," +
"所以請輸入星期值的第二個字母進行判斷");
f = sc.next();
if (f.length() == 1) {
S = f.charAt(0);
if (S == 'u' || S == 'U') {
System.out.println("星期二(Tuesday)");
break;
} else if (S == 'h' || S == 'H') {
System.out.println("星期四(Thursday)");
break;
} else {
System.out.println("輸入有誤,不能識別第二個字母,程序結束");
break;
}
} else {
System.out.println("輸入有誤,只能識別第一個字母,程序結束");
break; }
}
case 'w':
case 'W': {
System.out.println("星期三(Wednesday)");
break;
}
case 'f':
case 'F': {
System.out.println("星期五(Friday)");
break;
}
case 's':
case 'S': {
System.out.println("由於星期六(Saturday)和星期日(Sunday)都是S開頭," +
"所以需要輸入星期值的第二個字母進行判斷");
f = sc.next();
if (f.length() == 1) {
S = f.charAt(0);
if (S == 'a' || S == 'A') {
System.out.println("星期六(Saturday)");
break;
} else if (S == 'u' || S == 'u') {
System.out.println("星期日(Sunday)");
break;
} else {
System.out.println("輸入有誤,不能識別第二的字母,程序結束");
break;
}
} else {
System.out.println("輸入有誤,字母只能識別第一個字母,程序結束");
break;
}
}
default: {
System.out.println("輸入有誤,不能識別第一個字母,程序結束");
break;
}
}
} else {
System.out.println("輸入有誤,只能識別第一個字母,程序結束");
}
}
}