第四周上机练习

package test;
import java.util.Scanner;
public class LH {

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

2.

package test;
import java.util.Scanner;
public class LH {

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

3.

package test;
import java.util.Scanner;
public class LH {

    public static void main(String[] args) {
        System.out.println("请输入一个值x");
        Scanner input=new Scanner(System.in);
        int x=input.nextInt();
        if(x%5==0&&x%6==0){
            System.out.println(x+"能被5和6同时整除");
        }else if(x%5==0&&x%6!=0){
            System.out.println(x+"只能被5整除");
        }else if(x%5!=0&&x%6==0){
            System.out.println(x+"只能被6整除");
        }else if(x%5!=0&&x%6!=0){
            System.out.println(x+"不能被5或6整除");
        }
    }
}

4.

package test;
import java.util.Scanner;
import java.util.concurrent.SynchronousQueue;
public class LH {

    public static void main(String[] args) {
        System.out.println("请输入一个0到100的分数");
        Scanner input=new Scanner(System.in);
        int x=input.nextInt();
        if(x>=90){
            System.out.println("A");
        }else if(x>=80){
            System.out.println("B");
        }else if(x>=70){
            System.out.println("C");
        }else if(x>=60){
            System.out.println("D");
        }else if(x>=50){
            System.out.println("E");
        }else{
            System.out.println("F");
        }
    }
}

5.

package test;
import java.util.Scanner;
import java.util.concurrent.SynchronousQueue;
public class LH {

    public static void main(String[] args) {
        System.out.println("请输入三个数");
        Scanner input=new Scanner(System.in);
        int x=input.nextInt();
        int y=input.nextInt();
        int z=input.nextInt();
        int d;
        if (x>y){
            d=x;
            x=y;
            y=d;
            }
        if (x>z){
            d=x;
            x=z;
            z=d;
            }
        if (y>z){
            d=y;
            y=z;
            z=d;
            }
        System.out.println("三个数从小到大的顺序是"+x+y+z);
        }
    }

 

posted @ 2020-03-26 13:24  计算机1804梁浩  阅读(128)  评论(0编辑  收藏  举报