zoukankan      html  css  js  c++  java
  • 第三周作业

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

    import java.util.Scanner;
    
    public class first {
        public static void main(String[] args) {
            System.out.println("请输入一个年份");
            Scanner sc = new Scanner(System.in);
            int year = sc.nextInt();
            if ((year % 4 == 0 && year % 100 != 00) || (year % 400 == 0)) {
                System.out.println(year + "是一个闰年");
            } else {
                System.out.println(year + "是一个平年");
            }
        }
    
    
    }

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

    import java.util.Scanner;
    
    public class first {
        public static void main(String[] args) {
            System.out.println("请输入会员卡号");
            Scanner sc = new Scanner(System.in);
            int id = sc.nextInt();
            if (id % 1000 / 100 % 3 == 0) {
                System.out.println("幸运会员");
            } else {
                System.out.println("不是");
            }
    
        }
    
    }

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

    import java.util.Scanner;
    
    public class first {
        public static void main(String[] args) {
            System.out.println("请输入x的值");
            Scanner sc = new Scanner(System.in);
            int x = sc.nextInt();
            int y;
            if (x>0) {
                y=x+3;
                System.out.println("y的值为:"+y);
            } else if (x==0){
                y=0;
                System.out.println("y的值为:"+y);
            }else if (x<0){
                y=x*2-1;
                System.out.println("y的值为:"+y);
            }
    
        }
    
    }

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

    import java.util.Scanner;
    
    public class first {
        public static void main(String[] args) {
            System.out.println("三角形的三个边长");
            Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
    
            if ((a + b) > c && (a + c) > b && (b + c) > a) {
                System.out.println("可以构成三角形");
            }
            System.out.println("不可以构成三角型");
    
        }
    
    }
  • 相关阅读:
    常见规格液晶显示器尺寸/点距/分辨率
    Disk genius(Diskgenius)修复硬盘分区表
    IIS上注册.Net
    PowerDesigner中如何导入表结构
    关于VS命名空间的引用
    启动Word时出现“复制文件或文件夹时出错"对话框?
    能够删除的安卓(Android)系统自带程序详细列表和说明
    五种方法 解决Windows最大终端连接数
    查看本机打开的端口
    RAID技术概述
  • 原文地址:https://www.cnblogs.com/GEM520/p/12557453.html
Copyright © 2011-2022 走看看