day4

进行闰年计算

package test;

public class LeapYear {
	public static void main(String args[]){
		int tempYear = 2021;
		
		System.out.print("" + tempYear + " is ");
		if(!isLeapYear(tempYear)){
			System.out.print("NOT ");
		}//Of if
		System.out.println("a leap year.");
		
		tempYear = 2000;
		
		System.out.print("" + tempYear + " is ");
		if(!isLeapYear(tempYear)){
			System.out.print("NOT ");
		}//Of if
		System.out.println("a leap year.");
		
		tempYear = 2100;
		
		System.out.print("" + tempYear + " is ");
		if(!isLeapYear(tempYear)){
			System.out.print("NOT ");
		}//Of if
		System.out.println("a leap year.");
		
		tempYear = 2004;
		
		System.out.print("" + tempYear + " is ");
		if(!isLeapYear(tempYear)){
			System.out.print("NOT ");
		}//Of if
		System.out.println("a leap year.");
		
		
		System.out.println("Now use the second version.");
		
		tempYear = 2021;
		
		System.out.print("" + tempYear + " is ");
		if(! isLeapYearV2(tempYear)){
			System.out.print("NOT ");
		}//Of if
		System.out.println("a leap year.");
		
		tempYear = 2000;
		
		System.out.print("" + tempYear + " is ");
		if(! isLeapYearV2(tempYear)){
			System.out.print("NOT ");
		}//Of if
		System.out.println("a leap year.");
		
		tempYear = 2100;
		
		System.out.print("" + tempYear + " is ");
		if(! isLeapYearV2(tempYear)){
			System.out.print("NOT ");
		}//Of if
		System.out.println("a leap year.");
		
		tempYear = 2004;
		
		System.out.print("" + tempYear + " is ");
		if(! isLeapYearV2(tempYear)){
			System.out.print("NOT ");
		}//Of if
		System.out.println("a leap year.");
	}//Of main
	
	public static boolean isLeapYear(int paraYear){
	//boolean运算是与非
		if((paraYear % 4 == 0) && (paraYear % 100 != 0) || (paraYear % 400 == 0)){
		//=为运算符,==和!=是条件判断符号,&&为条件判断的求交集关系
			return true;
		}else{
			return false;
		}//Of if
	}//Of isLeapYear
	
	public static boolean isLeapYearV2(int paraYear){
		if (paraYear % 4 != 0){
			return false;
		}else if (paraYear % 400 == 0){
			return true;
		}else if (paraYear % 100 == 0){
			return false;
		}else{
			return true;
		}//Of if
	}//Of isLeapYear

}//Of class LeapYear

question:

println并不是使本行换行?而是让下一段print换行输出。

上一篇:python基础—day4 程序结构


下一篇:PHP代码审计学习_day4