zoukankan      html  css  js  c++  java
  • 第二次jave作业

    1.判断闰年

    import java.util.*;
    public class One {
         public static void main(String[] args) {
             Scanner input = new Scanner(System.in);
             System.out.println("请输入一个年份:");
             long year = input.nextLong();                               
             if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
                    System.out.println(year + "是闰年!");
             } else {
                    System.out.println(year + "不是闰年");
             }
       }
    
    }

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

    import java.util.*;
    public class One {
         public static void main(String[] args) {
             Scanner input = new Scanner(System.in);
             System.out.println("请输入卡号:");
             long hykh = input.nextLong();   
            if (hykh>999&&hykh<9999) {
                if (hykh%1000/100%3==0) {
                    System.out.println("宁是辛运会员");
                }else {
                    System.out.println("您八是幸运会员");
                }
            }else {
                System.out.println("请输入4位卡号");
            }
         }
    }

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

    import java.util.*;
    public class One {
         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*2-1));
            }else {
                System.out.println("y=0");
            }
    
         }
    }

     4.输入三个数判断是否能构成三角形

    import java.util.*;
    public class One {
         public static void main(String[] args) {
             Scanner input = new Scanner(System.in);
             System.out.println("输入三位数");
             int x = input.nextInt();  
             int y = input.nextInt();  
             int z = input.nextInt(); 
             if (x+y>z&&x+z>y&&y+z>x) {
                System.out.println("可以构成三角形");
            }else {
                System.out.println("不!");
            }
                
        

  • 相关阅读:
    Git&GitHUP总结
    SpringBoot 与任务
    SpringBoot中Scheme的使用
    SpringBoot的错误处理机制
    thymeleaf公共页面元素抽取
    redis 配置文件介绍 redis.conf
    SpringBoot如何实现国际化
    AttributeError: 'str' object has no attribute 'lowerr' Python常见错误
    TypeError: 'list' object cannot be interpreted as an integer Python常见错误
    TypeError: myMethod() takes no arguments (1 given) Python常见错误
  • 原文地址:https://www.cnblogs.com/rozenscarlet/p/12549779.html
Copyright © 2011-2022 走看看