现在的位置: 首页 > 综合 > 正文

java基础_从控制台输入年份月份,打印该月有多少天

2018年05月23日 ⁄ 综合 ⁄ 共 646字 ⁄ 字号 评论关闭
/*
从控制台输入年份月份,打印该月有多少天?(区分平年与闰年的2月)
*/
import java.util.Scanner;

public class TianShu {

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

}

抱歉!评论已关闭.