计算某年某月的天数 JAVA高手帮忙 救命啊

来源:百度知道 编辑:UC知道 时间:2024/06/17 13:54:02
题目:计算某年某月的天数
要求:通过键盘接收指定的年和月,判断该月的天数。
要点:月份可分为大月和小月,而二月份的天数跟是否闰年有关,所以对二月份要特殊处理。

JAVA高手帮忙 救命啊
高手 麻烦您把代码贴出来 如果能用我再追10分

import java.io.*;
import java.util.Scanner;

class DayTest
{
public static void main(String []args)throws IOException
{
int year = -1;
int month = -1;
Scanner in = new Scanner(System.in);
System.out.println("请输入年");
year = in.nextInt();
System.out.println("请输入月");
month = in.nextInt();

System.out.println(year+"年"+month+"月有"+days(year,month)+"天");

}

public static int days(int year,int month)
{
int days = 0;
if(month!=2)
{
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:days = 31 ;break;
case 4:
case 6:
case 9:
case 11:days = 30;

}
}
else
{

if(year%4==0 && year%100!=0 || year%400==0)
days = 29;
else d