键盘输入04


//导包
import java.util.Scanner;

public class IfDemo {
    public static void main(String[] args) {
        //创建对象
        Scanner s = new Scanner(System.in);
      
        //需求2:键盘录入一个星期数(1~7),输入对应的星期几;
        System.out.println("请输入一个星期数(1~7):");
        int week = s.nextInt();
        if (week == 1) {
            System.out.println("星期一");
        } else if (week == 2) {
            System.out.println("星期二");
        } else if (week == 3) {
            System.out.println("星期三");
        } else if (week == 4) {
            System.out.println("星期四");
        } else if (week == 5) {
            System.out.println("星期五");
        } else if (week == 6) {
            System.out.println("星期六");
        } else if (week == 7) {
            System.out.println("星期日");
        } else {
            System.out.println("请重新输入数字(1~7)");
        }     
    }
}

上一篇:《超越需求:敏捷思维模式下的分析》—第1章 1.4节迭代


下一篇:截取sql字符