2020.3.26 second time on board work

1. programming, the value of the input variable x, if it is 1, output x = 1, if it is 5, the output x = 5, if it is 10, x = 10 outputs, in addition to the above several values ​​are output x = none. (Knowledge: if conditional statement)

package com.itheima01;

import java.util.Scanner;

public class HelloWorld {
    public static void main(String[] args) {
         System.out.println("请输入一个数");
          Scanner input = new Scanner(System.in);
          int x = input.nextInt();
          if(x == 5) {
                 System.out.println("5");
          }
          else if(x == 10) {
                 System.out.println("10");
           }
          else if(x == 1) {
             System.out.println("1");
            }
           else {
            System.out.println("none");
           }
          }           
        }

2. To achieve the first question with a switch structure

package com.itheima01;

import java.util.Scanner;

public class HelloWorld {
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
         System.out.println("请输入一个数");
         int x=sc.nextInt();
            switch(x) {
                case 1: 
                case 5: 
                case 10:System.out.println("x="+x);break;
                default:System.out.println("x=none");
            }
    }
}

Determining whether a number is 3. 5 and 6 can be simultaneously divisible (5 and 6 can be divisible print), or can only be divisible by 5 (5 be divisible print), or can only be divisible by 6, (6 can print divisible ), can not be divisible by 5 or 6, (printing can not be divisible by 5 or 6)

package com.itheima01;

import java.util.Scanner;

public class HelloWorld {
    public static void main(String[] args) {
         System.out.println("请输入一个数");
          Scanner input = new Scanner(System.in);
          int x=input.nextInt();
             if (x%6==0&&x%5==0){
                 System.out.println("x="+x);
             }
             else if (x%5==0){
                 System.out.println("x="+x);
             }
             else if (x%6==0){
                 System.out.println("x="+x);
             }
             else if (x%5!=0&&x/6!=10){
                 System.out.println("x="+x);
             }
             else {
                 System.out.println("none");
             }
        }
}

4. Enter a score of 0 to 100, if not between 0 to 100, the print score is invalid, printing A (90-100), B (80-89) according to grade scores, C, D, E (knowledge: Condition statement if elseif)

package com.itheima01;

import java.util.Scanner;

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("根据分数判断评级");
          Scanner input = new Scanner(System.in);
          double a=input.nextDouble();
          if(a>=90&&a<=100){
              System.out.println("A");
          }else if(a>=80&&a<=89){
              System.out.println("B");
          }else if(a>=70&&a<79){
              System.out.println("C");
          }else if(a>=60&&a<=69){
              System.out.println("D");
          }else if(a>=50&&a<=59){
              System.out.println("E");
          }else 
              System.out.println("无效");
          }
}

5. Enter three integers x, y, z, please small to large number of these three outputs (knowledge: conditional statements)

package com.itheima01;

import java.util.Scanner;

public class HelloWorld {
    public static void main(String[] args) {
        int x=0,y=0,z=0;
        Scanner sc=new Scanner(System.in);
        x=sc.nextInt();
        y=sc.nextInt();
        z=sc.nextInt();
        int j;
        if(x>y){
            j=y;
            y=x;
            x=j;
        }
        if(x>z){
            j=z;
            z=x;
            x=j;
        }
        if(y>z){
            j=z;
            z=y;
            y=j;
        }
        System.out.println(x+" "+y+" "+z);
    }
}

 

Guess you like

Origin www.cnblogs.com/megumin/p/12573627.html