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

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

     1 import java.util.Scanner;
     2 
     3 public class testa {
     4 
     5 
     6     public static void main(String[] args) {
     7         // 1.输入一个年份,判断是不是闰年(能被4整除但不能被100整除,或者能被400整除) 
     8         Scanner input = new Scanner(System.in);
     9         System.out.println("请输入年份");
    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 
    21 }

     

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

     1 import java.util.Scanner;
     2 
     3 public class testb {
     4 
     5     public static void main(String[] args) {
     6         // 
     7         Scanner input = new Scanner(System.in);
     8         System.out.println("请输入四位会员卡号");
     9         int a=input.nextInt();
    10         switch(a%1000/100) {
    11         case 3:
    12         case 6:
    13         case 9:
    14             System.out.println("幸运会员");break;
    15         default:
    16             System.out.println("不是幸运会员");break;
    17         }
    18     
    19     }
    20 
    21 }

     

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

     1 import java.util.Scanner;
     2 
     3 public class testb {
     4 
     5     public static void main(String[] args) {
     6         // 
     7         Scanner input = new Scanner(System.in);
     8         System.out.println("请输入一个数");
     9         int a=input.nextInt();
    10         int y;
    11         if (a>0){
    12             y=a+3;
    13         }else if (a==0){
    14             y=0;            
    15         }else{
    16             y=(a*a)-1;
    17         }
    18         System.out.println(y);
    19         
    20     
    21     }
    22 
    23 }

     

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

     1 import java.util.Scanner;
     2 
     3 public class testb {
     4 
     5     public static void main(String[] args) {
     6         // 
     7         Scanner input = new Scanner(System.in);
     8         System.out.println("请输入三个数");
     9         int a=input.nextInt();
    10         int b=input.nextInt();
    11         int c=input.nextInt();
    12         if(a+b>c&&a+c>b&&b+c>a)
    13             System.out.println("能够成三角形");
    14         else
    15             System.out.println("不能构成三角形");
    16     }
    17         
    18 }

  • 相关阅读:
    oc基础第二天类与对象---1复习代码
    oc基础第二天类与对象---1复习
    oc基础第一天---类的方法,类与对象
    oc基础第一天---类与对象
    oc基础第一天---面向过程与面向对象
    oc基础第一天---c语言和oc语言的对比
    oc基础第一天---c语言与oc语言对比
    第一阶段c语言结晶说明
    mvc 使用json.net 替换JsonResult 默认序列化
    Mvc ModelBinder 一对多自定义数据格式 post提交
  • 原文地址:https://www.cnblogs.com/wuhaoovo/p/12544396.html
Copyright © 2011-2022 走看看