用 Java 请输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续 判断第二个字母。
1个回答
展开全部
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String result = "unknown";
String strRead = "";
while (true) {
System.out.println("please input:");
String input = strRead + s.next().toUpperCase().trim();
if (input.startsWith("M")) {
result = "Monday";break;
} else if (input.startsWith("W")) {
result = "Wednesday";break;
} else if (input.startsWith("F")) {
result = "Friday";break;
} else if (input.startsWith("TU")) {
result = "Tuesday";break;
} else if (input.startsWith("TH")) {
result = "Thurday";break;
} else if (input.startsWith("SA")) {
result = "Saturday";break;
} else if (input.startsWith("SU")) {
result = "Sunday";break;
} else if (input.startsWith("T") || input.startsWith("S")) {
strRead+=input;
continue;
} else
break;
}
System.out.println(result);
s.close();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询