输入年份和月份,判断月份有多少天

输入年份和月份,判断月份有多少天_第1张图片

//输入年份和月份,判断月份有多少天

import java.util.Scanner;

public class TestSum
{
	public static void main(String[] args) 
	{
		Scanner sc=new Scanner(System.in);
		System.out.println("请输入年份:");
		int year=sc.nextInt();
		System.out.println("请输入月份:");
		int month=sc.nextInt();
		if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
		{
			System.out.println(year+"年"+month+"月共有:31天");
		}
		else if(month==4||month==6||month==9||month==11)
		{
			System.out.println(year+"年"+month+"月共有:30天");
		}
		else 
		{
			if((year%4==0&&year%100!=0)||year%400==0)
			{
				System.out.println(year+"年"+month+"月共有:29天");
			}
			else
			{
				System.out.println(year+"年"+month+"月共有:28天");
			}
		}
	}

}

你可能感兴趣的:(Java笔记,eclipse)