JAVA编程 输入一个年份,判断是否是闰年(通过Calendar来实现)
2个回答
展开全部
import java.util.Calendar;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Calendar c = Calendar.getInstance();
System.out.println("输入年份:");
Scanner sc = new Scanner(System.in);
int year = sc.nextInt();
c.set(year, Calendar.DECEMBER, 31);
if (c.get(Calendar.DAY_OF_YEAR) == 366) {
System.out.println(year + "年是闰年");
} else {
System.out.println(year + "年平年");
}
}
}
展开全部
public void isLeapYear(int years){
Calendar cal=Calendar.getInstance();
cal.set(years,Calendar.DECEMBER,31);
if(cal.get(Calendar.DAY_OF_YEAR)==366){
System.out.println(years+"年是闰年");
}else{
System.out.println(years+"年平年");
}
}
Calendar cal=Calendar.getInstance();
cal.set(years,Calendar.DECEMBER,31);
if(cal.get(Calendar.DAY_OF_YEAR)==366){
System.out.println(years+"年是闰年");
}else{
System.out.println(years+"年平年");
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询