在java中接收用户输入的数字,如果1,则输出"星期一"...7,则输出"星期天".否则输出"输入不正确,请重新输入"

2024-11-25 23:25:50
推荐回答(1个)
回答1:

public class Test {
    public static void main(String[] args) {
        System.out.print("请输入:");
        Scanner scanner = new Scanner(System.in);
        String input = scanner.next();

        switch (input) {
            case "1":
                System.out.println("星期一");
                break;
            case "2":
                System.out.println("星期二");
                break;
            case "3":
                System.out.println("星期三");
                break;
            case "4":
                System.out.println("星期四");
                break;
            case "5":
                System.out.println("星期五");
                break;
            case "6":
                System.out.println("星期六");
                break;
            case "7":
                System.out.println("星期天");
                break;
            default:
                System.out.println("输入不正确,请重新输入");
        }
        scanner.close();
    }
}