Java判断闰年平年_java

 

 

Java判断闰年平年_Java_02

 

 

Java判断闰年平年_javascript_03

 

 

Java判断闰年平年_Java_04

 

 

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+"天");
}
}
}

作者:​​靠谱杨​​​


我可能不是天才,但我会努力成为人才。

更多日常分享尽在我的VX公众号:小杨的挨踢IT生活

Java判断闰年平年_java_05