键盘输入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)");
}
}
}
标签:week,Scanner,04,System,键盘输入,else,println,out 来源: https://blog.csdn.net/weixin_63992634/article/details/121962137