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

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

    package come.itheima01;
    import java.util.Scanner;
    public class Hello {
        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("是闰年");
            } else {
            System.out.println("不是闰年");
            }
            
    
            }
    
            }

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

    package come.itheima01;
    import java.util.Scanner;
    public class Hello {
        public static void main(String[] args) {
            Scanner input=new Scanner(System.in);
            System.out.println("请输入一4位会员卡号");
            int card=input.nextInt();
            if(card>=10000)
            {
                System.out.println("输入错误");
            }
            else if((card/100%10)%3==0){
                System.out.println("幸运会员");
            }
            else if((card/100%10)%3!=0)
            {
                System.out.println("不是幸运会员");
            }
        }
    }

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

    package come.itheima01;
    import java.util.Scanner;
    public class Hello {
         public static void main(String[] args) {
                Scanner input=new Scanner(System.in);
                System.out.println("请输入X的值:");
                double x=input.nextDouble();
                if(x>0)
                {
                    System.out.println("y="+(x+3));
                }
                else if(x==0){
                    System.out.println("y="+(x=0));
                }
                else if(x<0)
                {
                    System.out.println("y="+(x*2-1));
                }
            }
        }

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

    package come.itheima01;
    import java.util.Scanner;
    public class Hello {
         public static void main(String[] args) {
             Scanner input=new Scanner(System.in);
                System.out.println("请输入三角形的三个边:");
                double a=input.nextDouble();
                double b=input.nextDouble();
                double c=input.nextDouble();
                if(a+b>c && a+c>b && b+c>a)
                {
                    System.out.println("能构成三角形");
                }
                else
                {
                    System.out.println("不能构成三角形");
                }
           }
        }

  • 相关阅读:
    修改iptables防火墙规则解决vsftp登录后不显示文件目录的问题
    error: Refusing to undefine while domain managed save image exists
    linux 禁止ping
    Android图片加载框架Picasso最全使用教程3
    Android图片加载框架Picasso最全使用教程2
    Android图片加载框架Picasso最全使用教程1
    Android studio怎么修改文件名
    Android_Kotlin 代码学习
    Android Studio设置行宽、格式化断行
    使用Kotlin进行Android开发
  • 原文地址:https://www.cnblogs.com/songzhuo/p/12558223.html
Copyright © 2011-2022 走看看