Problem Description
输入年和月,判断该月有几天?
Input
输入年和月,格式为年\月。
Output
输出该月的天数。
Example Input
2009\1
Example Output
31
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
String s=in.nextLine();
String a[]=s.split("\\\\");
int year=Integer.parseInt(a[0]);
int month=Integer.parseInt(a[1]);
int flag=1;
if(year%4==0&&year%100!=0||year%400==0)
{flag=0;}
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
{System.out.println("31");}
else if(month==4||month==6||month==9||month==11)
{System.out.println("30");}
else if(month==2)
{
if(flag==1)
{System.out.println("28");}
else
{System.out.println("29");}
}
}
}

5714

被折叠的 条评论
为什么被折叠?



