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

    //1.输入一个年份,判断是不是闰年(能被4整除但不能被100整除,或者能被400整除)
    package hw;
    
    import java.util.Scanner;
    
    public class test {
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		
    		Scanner input = new Scanner(System.in);		
    		System.out.print("请输入任意年份:");		
    		int year = input.nextInt();		
    		if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0){			
    			System.out.println(year + "年是闰年");			
    		}else{			
    			System.out.println(year + "年不是闰年");			
    		}
    	}
    
    }
    

      

    //2.输入一个4位会员卡号,如果百位数字是3的倍数,就输出是幸运会员,否则就输出不是.
    package hw;
    
    import java.util.Scanner;
    
    public class test1 {
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    
    		Scanner input = new Scanner(System.in);	
    		System.out.print("请输入会员卡号:");	
    		int num = input.nextInt();
    		if (num >= 1000 && num <=9999) {			
                if(num / 100 % 10 % 3 == 0) {	
                    System.out.println("您是幸运会员"); 
                }else {
                	System.out.println("您不是幸运会员");
                	}
            }else {
            	System.out.println("您的会员卡号有误");
            	}   
    	}
    }
    

      

    /*3.已知函数,输入x的值,输出对应的y的值.
                          x + 3   ( x > 0 )
                   y =      0     ( x = 0 )
                          x2 –1  ( x < 0 )*/
    package hw;
    
    import java.util.Scanner;
    
    public class test2 {
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    
    		Scanner input = new Scanner(System.in);	
            System.out.print("请输入x的值:");
            int x = input.nextInt();
    		int y;
    		while( x > 0 ){
    			y = x + 3;
    			System.out.println("y的值为" + y);
    			break;
    		 }		
    		while( x == 0 ){
    			y = 0;
    			System.out.println("y的值为" + y);
    			break;
    		 }
    		while( x < 0 ){
    			y = x * 2 - 1;
    			System.out.println("y的值为" + y);
    			break;
    		 }
    	}
    
    }
    

      

    //4.输入三个数,判断能否构成三角形(任意两边之和大于第三边)
    package hw;
    
    import java.util.Scanner;
    
    public class test3 {
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    
    		Scanner input = new Scanner(System.in);	
            System.out.print("请输入第一条边:");
            int x = input.nextInt();
            System.out.print("请输入第二条边:");
            int y = input.nextInt();
            System.out.print("请输入第三条边:");
            int z = input.nextInt();
            if( x + y >= z  &&  x + z >= y  &&  y + z >= x){
                System.out.println("这三条边能构成三角形");
            }else {
                System.out.println("这三条边不能构成三角形");
                }
    	}
    }
    

      

  • 相关阅读:
    javaEE企业级基础介绍(一)
    SQL学习笔记系列(十)窗口函数
    SQL学习笔记系列(九)索引优化分析
    Tableau教程笔记
    淘宝用户行为分析--基于MySQL、Tableau
    Stop thinking,start living--《心灵奇旅》观后感
    SQL刷题
    SQL学习笔记系列(八)流程控制结构
    SQL学习笔记系列(七)存储过程和函数
    在超算系统上使用sbatch提交MXNet分布式训练任务
  • 原文地址:https://www.cnblogs.com/wu-di-821-821/p/12562585.html
Copyright © 2011-2022 走看看