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

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

     package com.itheima01;
    import java.util.Scanner;
    public class HelloWorld {
        public static void main(String[] args) {
             System.out.println("输入年份:");
             Scanner sc=new Scanner(System.in);
             String str=sc.nextLine();
             if(str.length()!=4){
                 System.out .print("请输入正确的四位数!");
                 return;
             }
             int year=Integer.parseInt(str);
             if((year%4==0&&year%100!=0||year%400==0)){
                 System.out.print(year+"是闰年!");
             }else{
                 System.out.println(year+"不是闰年!");
             }
        }
    }

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

    package com.itheima01;
    import java.util.Scanner;
    public class HelloWorld {
        public static void main(String[] args) {
             
             Scanner  input=new Scanner(System.in);
              System.out.println("请输入四位卡号");
              int a=input.nextInt();
             if(( a%1000/100)%3==0){
                 System.out.print( "是幸运会员");
             }else{
                 System.out.println( "不是幸运会员");
             }
        }
    }

    3.已知函数,输入x的值,输出对应的y的值。

                    x+3(x>0)

         y=     0(x=0)

              x*2-1(x<0)

    package com.itheima01;
    import java.util.Scanner;
    public class HelloWorld {
        public static void main(String[] args) {
             
             Scanner  input=new Scanner(System.in);
              System.out.println("输入x的值");
              float x=input.nextInt();
              float y;
             if(x>0){
                 y=x+3;
             }else if(x==0){
                 y=0;
             }else{
                 y=x*2-1;
             }
             System.out.println(y);
        }
    }

     

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

    package com.itheima01;
    import java.util.Scanner;
    public class HelloWorld {
        public static void main(String[] args) {
            Scanner AA = new Scanner(System.in);
            System.out.println("输入三个正整数");
            int a = AA.nextInt();
            int b = AA.nextInt();
            int c = AA.nextInt();
            if (a<=0||b<=0||c<=0){
            System.out.println("输入错误,请重新输入");
            }else if ((a+b)>c&&(a+c)>b&&(b+c)>a){
            System.out.println("能构成三角形");
            }else
            System.out.println("不能构成三角形");
    
        }
    }

  • 相关阅读:
    Springboot配置多数据源Rabbitmq
    SpringBoot 搭建 Rabbitmq
    SpringBoot 成Rabbitmq的疑惑记录
    Docker安装Redis关于Mounts denied解决
    使用Preferences写入注册表
    RSA解密报错 javax.crypto.BadPaddingException: Decryption error
    星座和生肖转化
    bio与nio
    跳表
    springboot+dubbo+zookeeper
  • 原文地址:https://www.cnblogs.com/zhangjiatong/p/12557543.html
Copyright © 2011-2022 走看看