import java.util.Scanner;
public class WeekJudge{
/**
* @param args
*/
public static void main(String[] args) {
System.out.print("请输入一个数,范围1-7:");
while (true) {
Scanner scanner = new Scanner(System.in);
try {
int x = scanner.nextInt();
if (x < 1 || x > 7) {
System.out.println("输入数据超出范围,请重新输入");
continue;
}
switch (x) {
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;
}
default: {
System.out.println("星期日");
break;
}
}
break;
} catch (Exception e) {
System.out.println("输入数据不是数字,请重新输入");
}
}
}
}
package com;
import java.util.Scanner;
public class WeekSwitch {
public static void main(String[] args) {
System.out.println("请输入一个整数:(范围:1-7) : ");
Scanner scanner = new Scanner(System.in);
int input = scanner.nextInt();
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("输入数据超出范围,请重新输入");
break;
}
}
}
哎,真心不想写,
public class ContainsBug{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int day =0;
while (!"".equals(day = in.nextInt())){
String dayStr ="星期";
switch (day){
case 1:
dayStr +="一";
break;
case 2:
dayStr +="二";
break;
case 3:
dayStr +="三";
break;
case 4:
dayStr +="四";
break;
case 5:
dayStr +="五";
break;
case 6:
dayStr +="六";
break;
case 7:
dayStr +="日";
break;
default:
dayStr = "输入数据超出范围,请重新输入";
break;
}
System.out.println(dayStr);
}
}
}
你这是需要画面和判读的程式码???