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

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


    import java.util.Scanner;
    public class ydy {

    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("不是闰年");
    }
    // TODO Auto-generated method stub

    }

    }

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


    import java.util.Scanner;
    public class ydy {
    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.println("是幸运会员");
    } else {
    System.out.println("不是幸运会员");
    }
    // TODO Auto-generated method stub

    }

    }

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

     1 package tset;
     2 import java.util.Scanner;
     3 public class demo {
     4     public static void main(String[] args) {
     5         Scanner input = new Scanner(System.in);
     6         System.out.println("请输入x的值(整数):");
     7         int x = input.nextInt();
     8         int y;
     9         if(x > 0) {
    10             y = x + 3;
    11             System.out.println("y的值是:" + y);
    12         }else if(x == 0) {
    13             System.out.println("y的值是:0");
    14         }else if(x < 0) {
    15             y = x * x - 1;
    16             System.out.println("y的值是:" + y);
    17         } 
    18 
    19     }
    20 
    21 }

     4.输入三个数,判断能否构成三角形(任意两边之和大于第三边)
    请在博客园班级提交,截止时间下周三中午12点.


    import java.util.Scanner;
    public class ydy {
    public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    System.out.println("请输入三角形的三边(整数):");
    int a = input.nextInt();
    int b = input.nextInt();
    int c = input.nextInt();
    int d = a + b;
    int e = a + c;
    int f = b + c;
    if(d > c && e > b && f > a) {
    System.out.println("能构成三角形");
    } else {
    System.out.println("不能构成三角形");
    }
    }
    }

  • 相关阅读:
    微信小程序_(校园视)开发视频的展示页_下
    微信小程序_(校园视)开发上传视频业务
    微信小程序_(校园视)开发视频的展示页_上
    微信小程序_(校园视)开发用户注册登陆
    微信小程序_(表单组件)checkbox与label
    微信小程序_(表单组件)button组件的使用
    微信小程序_(组件)icon、text、rich-text、progress四大基础组件
    微信小程序_(组件)可拖动movable-view
    微信小程序_(组件)swiper轮播图
    微信小程序_(组件)scroll-view可滚动视图
  • 原文地址:https://www.cnblogs.com/ydy128/p/12550397.html
Copyright © 2011-2022 走看看