java某年某月的天数

来源:互联网 发布:首席数据执行官 编辑:程序博客网 时间:2024/05/22 10:24

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