您的位置:首页 > 编程语言 > Java开发

java某年某月的天数

2017-04-15 16:32 288 查看

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");}
     }
 }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: