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

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

     1 package test1;
     2 import java.util.Scanner;
     3 
     4 public class test1 {
     5 
     6     public static void main(String[] args) {
     7         // TODO Auto-generated method stub
     8         System.out.println("请输入一个年份:");
     9         Scanner input=new Scanner(System.in);
    10         int a=input.nextInt();
    11         if(a%4==0||a%100!=0&&a%400==0){
    12             System.out.println("是闰年");
    13         }
    14         else{
    15             System.out.println("不是闰年");
    16         }
    17 
    18     }
    19 
    20 }

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

     1 package test1;
     2 import java.util.Scanner;
     3 
     4 public class test1 {
     5 
     6     public static void main(String[] args) {
     7         // TODO Auto-generated method stub
     8         System.out.println("请输入卡号:");
     9         Scanner input=new Scanner(System.in);
    10         int a=input.nextInt(),b;
    11         b=a/100%10;
    12         if(b%3==0){
    13             System.out.println("恭喜您是幸运会员!");
    14         }
    15         else{
    16             System.out.println("很可惜您不是幸运会员!");
    17         }
    18     }
    19 
    20 }

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

     1 package test1;
     2 import java.util.Scanner;
     3 
     4 public class test1 {
     5 
     6     public static void main(String[] args) {
     7         // TODO Auto-generated method stub
     8         System.out.println("请输入x的值:");
     9         Scanner input=new Scanner(System.in);
    10         int x=input.nextInt(),y;
    11         if(x>0){
    12             y=x+3;
    13             System.out.println(y);
    14         }
    15         else if(x==0){
    16             y=0;
    17             System.out.println(0);
    18         }
    19         else{
    20             y=x*2-1;
    21             System.out.println(y);
    22         }
    23     }
    24 
    25 }

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

     1 package test1;
     2 import java.util.Scanner;
     3 
     4 public class test1 {
     5 
     6     public static void main(String[] args) {
     7         // TODO Auto-generated method stub
     8         System.out.println("请输入a,b,c分别的值:");
     9         Scanner input=new Scanner(System.in);
    10         int a=input.nextInt();
    11         int b=input.nextInt();
    12         int c=input.nextInt();
    13         if(a+b>c&&a+c>b&&b+c>a){
    14             System.out.println("能构成三角形!");
    15         }
    16         else{
    17             System.out.println("不能构成三角形!");
    18         }
    19     }
    20 
    21 }

  • 相关阅读:
    Jmeter错误解析-明明写对了,确报404,原因是接口里多了个空格
    Jmeter+ant+svn+jenkins一键部署(四)--机器人发报告
    Django
    Linux下压缩解压文件夹+下载+删除命令
    VUE-安装
    Hadoop核心-MapReduce
    Pulsar 社区周报|2021-06-14~2021-06-20
    ApacheCon Asia 2021: Apache Pulsar 技术议题一览
    Pulsar 社区周报|2021-06-07~2021-06-13
    直播回顾|TGIP-CN 032:Apache Pulsar 快速上手实战
  • 原文地址:https://www.cnblogs.com/919753740yu/p/12560948.html
Copyright © 2011-2022 走看看