package 判断是否闰年;
import java.util.*;
public class TEST {
@SuppressWarnings({ "resource" })
public static void main(String[] args) {
System.out.println("请输入年份:");
Scanner sc = new Scanner(System.in);
Calendar c = Calendar.getInstance(); //1、获取日历对象
c.set(sc.nextInt(),2,1); // 2、把这个日历对象设置 为 3月1日。 (2月(0,1,2)==3月)
c.add(Calendar.DAY_OF_MONTH, -1); //3、然后月份减 1
String [] month = {"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月",};
String [] week = {"","星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
int num =c.get(Calendar.MONTH);
int num1 = c.get(Calendar.DAY_OF_WEEK); //4、获得星期几
System.out.println(c.get(Calendar.YEAR)+"年的"+month[num]+"一共"+
c.get(Calendar.DAY_OF_MONTH)+"天"+"\n"+week[num1]);
if(c.get(Calendar.DAY_OF_MONTH)==29){ //5、 然后做判断,如果 == 29 天 则是闰年
System.out.println("是闰年");
}else{
System.out.println("不是闰年");
}
}
}
|