这道题怎么做
设计程序,由用户输入一个整数到变量day。如果day是0,1,2,3,4,5,6,则输出Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday。如果用户输入不是0~6这几个数,则输出“Error”。这道题怎么做?
设计程序,由用户输入一个整数到变量day。如果day是0,1,2,3,4,5,6,则输出Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday。如果用户输入不是0~6这几个数,则输出“Error”。这道题怎么做?
2017-03-02
import java.util.Scanner;
public class test {
public static void main(String[] agrs){
Scanner input = new Scanner(System.in);
System.out.println("请输入0~6任意一个数字:");
int day = input.nextInt();
switch (day){
case 0:
System.out.println("Sunday");
break;
case 1:
System.out.println("Monday");
break;
case 2:
System.out.println("Tuesday");
break;
case 3:
System.out.println("Wednesday");
break;
case 4:
System.out.println("Thursday");
break;
case 5:
System.out.println("Friday");
break;
case 6:
System.out.println("Saturday");
break;
default:
System.out.print("Error");
break;
}
}
Scanner input= new Scanner(System.in);
System.out.println("please input the day");
int day=input.nextInt();
switch(day){
case 0:
System.out.print("Sunday");
break;
case 1:
System.out.print("Monday");
break;
case 2:
System.out.print("Tuesday");
break;
case 3:
System.out.print("Wednesday");
break;
case 4:
System.out.print("Thursday");
break;
case 5:
System.out.print("Friday");
break;
case 6:
System.out.print("Saturday");
break;
default:
System.out.print("Error");}
}
package Switch;
import java.util.Scanner;
public class test {
public static void main(String[] agrs){
Scanner input = new Scanner(System.in);
System.out.println("请输入0~6任意一个数字:");
int day = input.nextInt();
switch (day){
case 0:
System.out.println("Sunday");
break;
case 1:
System.out.println("Monday");
break;
case 2:
System.out.println("Tuesday");
break;
case 3:
System.out.println("Wednesday");
break;
case 4:
System.out.println("Thursday");
break;
case 5:
System.out.println("Friday");
break;
case 6:
System.out.println("Saturday");
break;
}
}
}
import java.util.*;
public class HelloWorld {
//完成 main 方法
public static void main(String[] args) {
System.out.print("输入数字(0-6):");
int day=input.nextInt();
swicth(day){
case 0:
System.out.print("Sunday");
break;
case 1:
System.out.print("Monday");
break;
case 2:
System.out.print("Tuesday");
break;
case 3:
System.out.print("Wednesday");
break;
case 4:
System.out.print("Thursday");
break;
case 5:
System.out.print("Friday");
break;
case 6:
System.out.print("Saturday");
break;
default:
System.out.print("Error");}
}
}
System.out.print("输入day:");
int day=input.nextInt();
swicth(day){
case 1:
System.out.print("Sunday");
break;
case 2:
System.out.print("Monday");
break;
case 3:
System.out.print("Tuesday");
break;
case 4:
System.out.print("Wednesday");
break;
case 5:
System.out.print("Thursday");
break;
case 6:
System.out.print("Friday");
break;
case 7:
System.out.print("Saturday");
break;
default:
System.out.print("Error");
System.out.print("输入day:");
int day=input.nextInt();
swicth(day){
case 1:
System.out.print("Sunday");
break;
case 2:
System.out.print("Monday");
break;
case 3:
System.out.print("Tuesday");
break;
case 4:
System.out.print("Wednesday");
break;
case 5:
System.out.print("Thursday");
break;
case 6:
System.out.print("Friday");
break;
case 7:
System.out.print("Saturday");
break;
default:
System.out.print("Error");
举报