用Calendar方法,判断年份是平年还是闰年

package practise;

import java.util.Calendar;
import java.util.Scanner;

public class Xzqz3 {

public static void main(String[] args) {
	System.out.println("请输入年份");
	Scanner sc=new Scanner(System.in);
	int year=sc.nextInt();
	
	Calendar c=Calendar.getInstance();
	c.set(Calendar.YEAR,year);
	c.set(Calendar.MONTH,2);
	c.set(Calendar.DAY_OF_MONTH,1);
	
	c.add(Calendar.DAY_OF_YEAR,-1);
	
	int day=c.get(Calendar.DAY_OF_MONTH);
	if(day==29) {
		System.out.println(year+"年是闰年");
	}else {
		System.out.println(year+"年是平年");
	}
}

}

你可能感兴趣的:(编程语言)