package com.zuoye;
import java.util.Scanner;
//4.请输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续 判断第二个字母
public class Test4 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入星期的第一个字母:");
String[] arr = {"","M","TU","W","Th","F","Sa","Su"};
String[] arrWeek ={"","一","二","三","四","五","六","日"};
while(true){
String s1 = sc.nextLine().toUpperCase();
for (int i = 1; i < arr.length; i++) {
if (arr[i].toUpperCase().equals(s1) ) {
System.out.println("星期"+arrWeek[i]);
return;
}
if (arr[i].toUpperCase().startsWith(s1)) {
System.out.println("请再输入一个字母:");
String s2 = sc.nextLine().toUpperCase();
s1 = s1+s2;
i--;
}
}
System.out.println("没有该星期:");
}
}
}
|