Java经典编程题–判断星期几

请输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续判断第二个字母。

public class Example26 { public static void main(String[] args) { f(); } public static void f() { System.out.println("请输入星期的第一个大写字母:"); char ch = 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("请输入星期的第二个字母:"); char ch2 = getChar(); if (ch2 == 'U') { System.out.println("该字母对应的是Tuesday。"); } else if (ch2 == 'H') { System.out.println("该字母对应的是Thursday。"); } else { System.out.println("无此写法!"); } };break; case 'S': { System.out.println("请输入星期的第二个字母:"); char ch2 = getChar(); if (ch2 == 'U') { System.out.println("该字母对应的是Sunday"); } else if (ch2 == 'A') { System.out.println("该字母对应的是Saturday"); } else { System.out.println("无此写法!"); } };break; default: System.out.println("无法判断你输入的字符!!!"); } } public static char getChar() { @SuppressWarnings("resource") Scanner s = new Scanner(System.in); String str = s.nextLine(); char ch = str.charAt(0); if (ch < 'A' || ch > 'Z') { System.out.println("首字母输入错误,请重新输入!!!"); ch = getChar(); } return ch; }}

以上就是Java经典编程题–判断星期几的详细内容,更多请关注其它相关文章!

偶尔被惊鸿一瞥的美丽吸引;或者走进一条深沉深沉的巷道,

Java经典编程题–判断星期几

相关文章:

你感兴趣的文章:

标签云: