第三周作业

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

package com.a01;

 

import java.util.*;

 

public class hellowold {

    public static void main(String[] args) {

       Scanner input = new Scanner(System.in);

       System.out.println("输入一个年份");

       int a = input.nextInt();

       if ((a % 4 == 0 && a % 100 != 0) || a % 400 == 0) {

           System.out.println(a + "是闰年");

       } else {

           System.out.println(a + "不是闰年");

       }

    }

}

2.输入一个4位会员卡号,如果百位数字是3的倍数,就输出是幸运会员,否则就输出不是.

package com.a01;

 

import java.util.*;

 

public class hellowold {

    public static void main(String[] args) {

       Scanner input = new Scanner(System.in);

       System.out.println("输入一个四位卡号");

       int a = input.nextInt();

       if (a / 100 % 10 % 3 == 0 && a / 100 % 10 != 0) {

           System.out.println(a + "是幸运会员");

       } else {

           System.out.println(a + "不是");

       }

    }

}

3.已知函数,输入x的值,输出对应的y的值. x + 3 ( x > 0 ) y = 0 ( x = 0 ) x2 –1 ( x < 0 )

package com.a01;

 

import java.util.*;

 

public class hellowold {

    public static void main(String[] args) {

       Scanner input = new Scanner(System.in);

       System.out.println("输入x的值");

       int x = input.nextInt();

       if (x > 0) {

           System.out.println("y=" + (x + 3));

       } else if (x == 0) {

           System.out.println("y=" + x);

       } else {

           System.out.println("y=" + (x * 2 - 1));

       }

    }

}

4.输入三个数,判断能否构成三角形(任意两边之和大于第三边) 

package com.a01;

 

import java.util.*;

 

public class hellowold {

    public static void main(String[] args) {

       Scanner input = new Scanner(System.in);

       System.out.println("取3条边预构成一个三角形");

       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("不能构成三角形");

       }

    }

}

原文地址:https://www.cnblogs.com/hyonf/p/12561929.html