代码改变世界

java中switch语句的使用-0511

2018-05-14 11:26  yelena  阅读(746)  评论(0编辑  收藏  举报
import java.util.Scanner;
class Demo01 
{
    public static void main(String[] args) 
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入");
        int week = sc.nextInt();
        switch (week)
        {
        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;
        }
    }
}
import java.util.Scanner;
class Demo03 
{
    public static void main(String[] args) 
    {
        Scanner sc = new Scanner(System.in);
        /*System.out.println("输入数值");
        int score = sc.nextInt();
        switch (score)
        {
            case 90:
            case 91:
            case 92:
            case 93:
            case 94:
            case 95:
            case 96:
            case 97:
            case 98:
            case 99:
            case 100:
                System.out.println("A等");
            break;
            case 80:
            case 81:
            case 82:
            case 83:
            case 84:
            case 85:
            case 86:
            case 87:
            case 88:
            case 89:
                System.out.println("B等");
            break;
            case 70:
            case 71:
            case 72:
            case 73:
            case 74:
            case 75:
            case 76:
            case 77:
            case 78:
            case 79:
                System.out.println("C等");
            break;
            case 60:
            case 61:
            case 62:
            case 63:
            case 64:
            case 65:
            case 66:
            case 67:
            case 68:
            case 69:
                System.out.println("D等");
            break;
            default:
                System.out.println("E等");
            break;
        }*/
  
        
        /*Scanner sc = new Scanner(System.in);
        System.out.println("请输入成绩");
        int score = sc.nextInt();
        switch (score>=0?(score>=60?(score>=70?(score>=80?(score>=90?(score>100?6:5):4):3):2):1):0)
        {
          case (5):
          System.out.println("A等");
          break;
          case (4):
          System.out.println("B等");
          break;
          case (3):
          System.out.println("C等");
          break;
          case (2):
          System.out.println("D等");
          break;
          case (1):
          System.out.println("E等");
          break;
          case (0):
          case (6):
          System.out.println("输入有误");
          break;
        }*/


        /*System.out.println("请输入工龄");
        int gl = sc.nextInt();
        System.out.println("请输入基础工资");
        int jcgz = sc.nextInt();
        int gz = 0;
        if(gl>=10 && gl<15){
             gz = jcgz + 5000;
             System.out.println("您目前工作了"+gl+"年,基础工资为:"+jcgz+",应涨工资为:5000元"+",涨后工资为"+gz+"元");
        }else if(gl>=5 && gl<10){
             gz = jcgz + 2500;
             System.out.println("您目前工作了"+gl+"年,基础工资为:"+jcgz+",应涨工资为:2500元"+",涨后工资为"+gz+"元");
        }else if(gl>=3 && gl<5){
             gz = jcgz + 1000;
             System.out.println("您目前工作了"+gl+"年,基础工资为:"+jcgz+",应涨工资为:1000元"+",涨后工资为"+gz+"元");
        }else if(gl>=1 && gl<3){
             gz = jcgz + 500;
             System.out.println("您目前工作了"+gl+"年,基础工资为:"+jcgz+",应涨工资为:500元"+",涨后工资为"+gz+"元");
        }else if(gl>=0 && gl<1){
             gz = jcgz + 200;
             System.out.println("您目前工作了"+gl+"年,基础工资为:"+jcgz+",应涨工资为:200元"+",涨后工资为"+gz+"元");
        }else{
             System.out.println("输入有误");
        }*/
        int[] arr = new int[3];
        System.out.print("第一个数字");
        arr[0] = sc.nextInt();
        System.out.print("第二个数字");
        arr[1] = sc.nextInt();
        System.out.print("第三个数字");
        arr[2] = sc.nextInt();
        int a = 0;
        for(int i = 0;i<arr.length-1;i++){
           for(int j=i+1;j<arr.length;j++){
               if(arr[i]>arr[j]){
                  a = arr[i];
                  arr[i] = arr[j];
                  arr[j] = a;
              }
           }
        }
        System.out.println(arr[0]);
        System.out.println(arr[1]);
        System.out.println(arr[2]);
    }
    }