java第四次作业

//第一题 输入一个年份,判断是不是闰年(能被4整除但不能被100整除,或者能被400整除)

import
java.util.Scanner; public class Zuoye1 { // TODO Auto-generated constructor stub public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.println("输入一个年份"); int year=input.nextInt(); if (year%4==0&&year%100!=0||year%400==0) { System.out.println("这是闰年"); }else { System.out.println("这不是闰年"); } } }

 

 

import java.util.Random;
import java.util.Scanner;

public class Zuoye1 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input = new Scanner(System.in);
        System.out.println("输入四个数字");
        int number = input.nextInt();
        int baiwei = number/100%10;
        Random r = new Random();
        int a=r.nextInt(10);
        if (baiwei==a) {
            System.out.println("您是幸运会员");
        }else {
            System.out.println("不是");
        }
    }

}

 

 

 

 

import java.util.Scanner;

public class Zuoye1 {

    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();
        int y=0;
        if (x>0) {
            y=x+3;
        }else if (x==3) {
            y=0;
            
        }else {
            y=x*2-1;
        }System.out.println("y="+y);

    }

}

 

 

 

 

import java.util.Scanner;

public class Zuoye1 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input = new Scanner(System.in);
        System.out.println("输入一个数");
        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("x=none");
        }

    }

}

 

 

 

import java.util.Scanner;

public class Zuoye1{

    public static void main(String[] args) {
        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) {
            System.out.println("能被5整除");
        } else if (a % 6 == 0) {
            System.out.println("能被6整除");
        } else {
            System.out.println("不能被5或6整除");
        }

    }

    // TODO Auto-generated method stub

}

 

 

posted @ 2021-03-28 13:39  刘德广  阅读(52)  评论(0编辑  收藏  举报