这道题怎么做

来源:4-14 Java 循环语句之多重循环

慕工程4995296

2017-03-02 11:51

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

写回答 关注

6回答

  • 慕函数8491977
    2017-03-02 19:50:28

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

    }

  • 鬼谷子夜
    2017-03-02 13:33:36

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

    }



  • Xu楚智
    2017-03-02 13:23:30

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

  • 小鱼儿5168
    2017-03-02 12:56:03

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

        }

    }


  • 慕粉3312078
    2017-03-02 12:51:49

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


  • 赵又廷
    2017-03-02 12:43:20

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

Java入门第一季(IDEA工具)升级版

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

1165172 学习 · 17581 问题

查看课程

相似问题