Java判断闰年平年
package leap;
import java.util.Scanner;
public class Leap {
public static void main(String args[])
{
int year; //年
int month; //月
int day = 0; //日
boolean flag; //判断标志
System.out.print("请依次输入年和月:"+'\n');
Scanner sc=new Scanner(System.in);
year=sc.nextInt();
month=sc.nextInt();
if(year%400==0||(year%4==0&&year%100!=0))
{
flag=true;
System.out.println(year+"年是闰年!");
}
else {
flag=false;
System.out.println(year+"年是平年!");
}
if(flag==true)
{
switch(month)
{
case 1:
day=31;
break;
case 2:
day=29;
break;
case 3:
day=31;
break;
case 4:
day=30;
break;
case 5:
day=31;
break;
case 6:
day=30;
break;
case 7:
case 8:
day=31;
break;
case 9:
day=30;
break;
case 10 :
day=31;
break;
case 11:
day=30;
break;
case 12:
day=31;
break;
}
System.out.println("且"+year+"年的"+month+"月有"+day+"天");
}
else
{
switch(month)
{
case 1:
day=31;
break;
case 2:
day=28;
break;
case 3:
day=31;
break;
case 4:
day=30;
break;
case 5:
day=31;
break;
case 6:
day=30;
break;
case 7:
case 8:
day=31;
break;
case 9:
day=30;
break;
case 10 :
day=31;
break;
case 11:
day=30;
break;
case 12:
day=31;
break;
}
System.out.println("且"+year+"年的"+month+"月有"+day+"天");
}
}
}
好看请赞,养成习惯:) 本文来自博客园,作者:靠谱杨, 转载请注明原文链接:https://www.cnblogs.com/rainbow-1/p/13357906.html
欢迎来我的51CTO博客主页踩一踩 我的51CTO博客
文章中的公众号名称可能有误,请统一搜索:靠谱杨的秘密基地