为了账号安全,请及时绑定邮箱和手机立即绑定

这道题怎么做

设计程序,由用户输入一个整数到变量day。如果day是0,1,2,3,4,5,6,则输出Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday。如果用户输入不是0~6这几个数,则输出“Error”。这道题怎么做?

正在回答

6 回答

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;    
    }

}

0 回复 有任何疑惑可以回复我~

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");}

}



0 回复 有任何疑惑可以回复我~

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;
    }
    }
}

0 回复 有任何疑惑可以回复我~

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");}

    }

}


0 回复 有任何疑惑可以回复我~

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");


0 回复 有任何疑惑可以回复我~

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");

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Java入门第一季(IDEA工具)升级版
  • 参与学习       1165458    人
  • 解答问题       17585    个

0基础萌新入门第一课,从Java环境搭建、工具使用、基础语法开始

进入课程

这道题怎么做

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信