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

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

    import java.util.Scanner;
    public class apple {
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		  System.out.print("输入年份:");
    		   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.print(year+"不是闰年!");  
    			   }
    	}
    
    }
    

      

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

    import java.util.Scanner;
    public class apple {
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		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("不是幸运会员");
    		 }
    		 
    	}
    			   }
    

      

    3.

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

    import java.util.Scanner;
    public class apple {
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		System.out.println("请输入x的值");
    		  Scanner input=new Scanner(System.in);
    		  float x=input.nextInt();
    		  float y;
    		  if(x>0){
    			  y=x+3;
    		  }else if(x==0){
    			  y=0;
    		  }else{
    			  y=x*x-1;
    		  }
    		  System.out.println("y的值是"+y);
    		 
    	}
    			   }
    

      

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

    import java.util.Scanner;
    public class apple {
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		System.out.println("请输入三角形的三条边");
    		  Scanner input=new Scanner(System.in);
    		  int a=input.nextInt();
    		  int b=input.nextInt();
    		  int c=input.nextInt();
    		  if((a+b)>c&&(a+c)>b&&(b+c)>a){
    			  System.out.println("YES");
    		  }
    		  else{
    			  System.out.println("NO");
    		  } 
    	}
    			   }
    

      

  • 相关阅读:
    02_离线计算系统_第2天(HDFS详解)
    01_离线计算系统_第1天(HADOOP快速入门)
    01_离线计算系统_第1天(HADOOP快速入门)
    第4天 java高级特性增强 ---有用 第一遍
    038_字符串的转义
    037_标准化日期代码
    036_js中的字符串比较大小
    035_jQaury中的each()循环
    034_json对象字符串长什么样子?
    033_SpringMVC返回String,view,Object的原理
  • 原文地址:https://www.cnblogs.com/qq007/p/12541527.html
Copyright © 2011-2022 走看看