java中,从键盘输入一位整数,当输入1~7时

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

import java.util.Scanner;
public class test
{
public static void main(String[]args)
{
while(true){
Scanner sc = new Scanner(System.in);
int num=0;
do{
if (num>7||num<0) {
System.out.println("输入有误!");
break;
}else{
System.out.println("请输入0-7的数字:");
num = sc.nextInt();
switch(num){
case 1: System.out.println("MON");break;
case 2: System.out.println("TUE");break;
case 3: System.out.println("WED");break;
case 4: System.out.println("THU");break;
case 5: System.out.println("FRI");break;
case 6: System.out.println("SAT");break;
case 7: System.out.println("SUN");break;
}
}
}
while(num!=0);
if (num==0) {
System.out.println("结束");
break;
}
}
}
}