第四次作业

1.编写程序, 输入变量x的值,如果是1,输出x=1,如果是5,输出x=5,如果是 10,输出 x=10,除了以上几个值,都输出x=none。(知识点:if条件语句)

package kkkkkkkk;

import java.util.Scanner;

public class rrrr {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input =new Scanner(System.in);
        System.out.println("输入X");
        int x=input.nextInt();
        if (x==1) {
            System.out.println("1");
        } else if(x==5){
            System.out.println("5");
        } else if(x==10){
            System.out.println("10");
        } else{
            System.out.println("none");
        }
    }

}

2.用switch结构实现第1题

package kkkkkkkk;

import java.util.Scanner;

public class rrrr {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input =new Scanner(System.in);
        System.out.println("输入X");
        int x=input.nextInt();
        switch (x) {
        case 1:System.out.println("1");
            break;
        case 5:System.out.println("5");
        break;
        case 10:System.out.println("10");
        break;
        default:System.out.println("none");
            break;
        }
    }

}

3.判断一个数字是否能被5和6同时整除(打印能被5和6整除),或只能被5整除(打印能被5整 除),或只能被6整除,(打印能被6整除),不能被5或6整除,(打印不能被5或6整除)

package kkkkkkkk;

import java.util.Scanner;

public class rrrr {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input =new Scanner(System.in);
        System.out.println("输入X");
        int x=input.nextInt();
        if (x%5==0&&x%6==0) {
            System.out.println("能被5和6整除");
        } else if(x%5==0) {
            System.out.println("能被5整除");}
            else if(x%6==0){
                System.out.println("能被6整除");
            }else{
                System.out.println("不成立");
            }
    }
}

4.输入一个0~100的分数,如果不是0~100之间,打印分数无效,根据分数等级打印 A(90-100),B(80-89),C,D,E(知识点:条件语句if elseif)

package kkkkkkkk;

import java.util.Scanner;

public class rrrr {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input =new Scanner(System.in);
        System.out.println("输入成绩X");
        int x=input.nextInt();
        switch (x/10) {
        case 10:
        case 9:
        System.out.println("A");break;
        case 8:
        System.out.println("B");break;
        case 7:
        System.out.println("c");break;
        case 6:
        System.out.println("D");break;
        case 5:
        System.out.println("E");break;
        default:System.out.println("不成立");
            break;
        }
    }
}

输入三个整数x,y,z,请把这三个数由小到大输出(知识点:条件语句)

package kkkkkkkk;

import java.util.Scanner;

public class rrrr {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input =new Scanner(System.in);
        int x=0,y=0,z=0;
        System.out.println("输入三个数");
        x=input.nextInt();
        y=input.nextInt();
        z=input.nextInt();
        int min=x;
        if(x>y){int r=x;x=y;y=r;}
        if(x>z){int r=x;x=z;z=r;}
        if(y>z){
            System.out.println(x+"<"+z+"<"+y);
        }else{System.out.println(x+"<"+y+"<"+z);
        }
        
    }
}
原文地址:https://www.cnblogs.com/xuwei123456/p/12573334.html