第四次java作业

第一题

import java.util.Scanner;

public class Exe01 {

    /**
     * @param args
     */
    public static void main(String[] args) {

        System.out.println("请输入年份");
        Scanner input = new Scanner(System.in);
        int a = input.nextInt();
        if (a % 4 == 0 || a % 100 != 0 && a % 400 == 0) {
            System.out.println(a + "是闰年");
        } else {
            System.out.println(a + "不是闰年");
        }
    }
}

第二题

import java.util.Random;
import java.util.Scanner;
public class text2 {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Random r=new Random();
        Scanner input=new Scanner(System.in);
        int a=r.nextInt(10);
        System.out.println("幸运数字是"+a);        
        System.out.println("请输入一个四位数");
        int b=input.nextInt();
        if(b%100/100==a){
            System.out.println("恭喜您是幸运会员");            
        }
        else{
            System.out.println("很遗憾您不是幸运会员");
        }
    }     

}

第三题

import java.util.Scanner;

public class exe04 {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println("输入x");
        Scanner input = new Scanner(System.in);
        int x = input.nextInt();
        int y;
        if (x > 0) {
            y = x + 3;
            System.out.println(y);
        } else if (x == 0) {
            y = 0;
            System.out.println(y);
        } else if (x < 0) {
            y = x * 2 - 1;
            System.out.println(y);
        }
    }

}

第四题

import java.util.Scanner;

public class ese05 {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println("请输入三个数");
        Scanner input = new Scanner(System.in);
        int a = input.nextInt();
        int b = input.nextInt();
        int c = input.nextInt();
        if (a + b > c && a + c > b && b + c > a) {
            System.out.println("能构成三角形");
        } else {
            System.out.println("不能构成撒三角形");
        }
    }

}

第五题

import java.util.Scanner;

public class text {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input=new Scanner(System.in);
        System.out.println("输入年份");
                int b=input.nextInt();
                System.out.println("输入月份");
                int a=input.nextInt();
                if (a==2) {
                   if (b%4==0&&b%100!=0||b%400==0) {
                   System.out.println("该月份有29天");    
                   }
                   else{
                   System.out.println("该月份有28天");
                   }
               }
               if (a==1||a==3||a==5||a==7||a==8||a==10||a==12) {
                  System.out.println("该月份有31天");
              }
              if (a==11||a==4||a==6||a==9){
                 System.out.println("该月份有30天");
             }
    }
}

第六题

import java.util.Scanner;

public class text {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input=new Scanner(System.in);
        System.out.println("输入成绩");
        int a=input.nextInt();
        int b=a/10;
        switch (b) {
        case 10:
            System.out.println("等级为A");
            break;
        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;
        case 4:
            System.out.println("等级为E");
            break;
        case 3:
            System.out.println("等级为E");
            break;
        case 2:
            System.out.println("等级为E");
            break;
        case 1:
            System.out.println("等级为E");
            break;
        case 0:
            System.out.println("等级为E");
            break;

        default:
            break;
        }
    }

}

第七题

import java.util.Scanner;

public class text {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input=new Scanner(System.in);
        System.out.println("输入一个数字");
        int x=input.nextInt();
        if(x%2==0){
            System.out.println("偶数");
        }else {
            System.out.println("奇数");
            }
    }

}

第八题

import java.util.Scanner;

public class text {

    /**
     * @param args
     */
    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||x==5||x==10){
            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;
            }
        }
        else{
            System.out.println("x=none");
        }
        // TODO Auto-generated method stub

    }
}

第九题

import java.util.Scanner;

public class text {

    /**
     * @param args
     */
     public static void main(String[] args) {
            // TODO Auto-generated method stub
            Scanner input=new Scanner(System.in);
            System.out.println("输入一个数字");
            int a=input.nextInt();
            if(a%5==0&&a%6==0){
                System.out.println("能被5和6整除");
            }else if(a%5==0&&a%6!=0){
                System.out.println("能被5整除");
            }else if(a%6==0&&a%5!=0){
                System.out.println("能被6整除");
            }else if(a%5!=0&&a%6!=0){
                System.out.println("不能被5或6整除");
            }
        }

}

posted @ 2021-03-30 15:10  w-j  阅读(26)  评论(0编辑  收藏  举报