从键盘上输入一位整数,当输入1~7时,显示对应的英文星期名称的缩写。

//需要输入,须先声明扫描器
import java.util.Scanner;
public class S {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int num = 0;
String day = “”;
System.out.print(“请输入1~7的整数(输入0结束):”);
num = input.nextInt();
do{
switch (num) {
case 1:
day = “今天是MON”;
System.out.println(day);
break;
case 2:
day = “今天是TUE”;
System.out.println(day);
break;
case 3:
day = “今天是WED”;
System.out.println(day);
break;
case 4:
day = “今天是THU”;
System.out.println(day);
break;
case 5:
day = “今天是FRI”;
System.out.println(day);
break;
case 6:
day = “今天是SAT”;
System.out.println(day);
break;
case 7:
day = “今天是SUN”;
System.out.println(day);
break;
default:
System.out.println(“输入错误!请重新输入!”);
break;
}
System.out.print(“请输入1~7的整数(输入0结束):”);
num = input.nextInt();
}while(num!=0);
System.out.println(“程序结束!”);
}
}

你可能感兴趣的:(java循环)