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

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

     1 package as;
     2 import java.util.Scanner;
     3 public class unll {
     4     public static void main(String[] args) {
     5         // TODO Auto-generated method stub
     6         System.out.println("输入年份:");
     7         Scanner sc=new Scanner(System.in);
     8         String str=sc.nextLine();
     9         if(str.length()!=4){
    10             System.out .print("请输入正确的四位数!");
    11             return;
    12         }
    13         int year=Integer.parseInt(str);
    14         if((year%4==0&&year%100!=0||year%400==0)){
    15             System.out.print(year+"是闰年!");
    16         }else{
    17             System.out.println(year+"不是闰年!");
    18         }
    19     }
    20 }

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

    package as;
    import java.util.Scanner;
    public class unll {
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            System.out.println("输入4位会员卡号");
            Scanner input=new Scanner(System.in);
            int a = input.nextInt();
            if(a/100%10%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)

    package as;
    import java.util.Scanner;
    public class unll {
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            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.输入三个数,判断能否构成三角形(任意两边之和大于第三边)

     1 package as;
     2 import java.util.Scanner;
     3 public class unll {
     4     public static void main(String[] args) {
     5         // TODO Auto-generated method stub
     6         Scanner AA = new Scanner(System.in);
     7         System.out.println("输入三个正整数");
     8         int a = AA.nextInt();
     9         int b = AA.nextInt();
    10         int c = AA.nextInt();
    11         if (a<=0||b<=0||c<=0){
    12         System.out.println("输入错误,请重新输入");
    13         }else if ((a+b)>c&&(a+c)>b&&(b+c)>a){
    14         System.out.println("能构成三角形");
    15         }else
    16         System.out.println("不能构成三角形");
    17 
    18     }
    19 }

  • 相关阅读:
    平面切圆柱面的椭圆绘制
    抛物面倾斜体积积分
    计算误差函数的积分--erf(x)
    三棱椎的体积
    Mac平台上OpenCV开发环境搭建
    仿新浪右下角视频弹窗(视频弹出广告)播放器
    python爬虫之Scrapy 使用代理配置
    ip地址定位库
    python 使用 redis expire属性设置访问时间间隔
    如何做将两张图片合二为一
  • 原文地址:https://www.cnblogs.com/zxp-0101/p/12557972.html
Copyright © 2011-2022 走看看