编写程序,提示用户输入月份和年份,然后显示这个月份的天数.java语言编写

 我来答
历盆郁7
2013-10-14 · TA获得超过4277个赞
知道大有可为答主
回答量:1795
采纳率:100%
帮助的人:917万
展开全部
import java.util.Scanner;

public class $ {

    private static int[] DAYS = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        System.out.print("输入年份:");
        int year = in.nextInt();
        System.out.print("输入月份:");
        int month = in.nextInt();

        String str = year + "-" + month + ":";

        // 闰年二月份
        if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0) && month == 2) {
            str += 29;
        } else {
            str += DAYS[month - 1];
        }

        System.out.println(str);
    }
}
sgjhfree
2013-10-14 · 超过13用户采纳过TA的回答
知道答主
回答量:59
采纳率:0%
帮助的人:7.9万
展开全部
输入参数 1900 2

返回:
The month days is 28
bye!

代码如下:

package com.common.test
public class CaculateDays {
public static void main(String argvs[]) {
int year = 1;
int month = 1;
int monthdays[] = null;
int monthdays1[] = new int[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31,
30, 31 };
int monthdays2[] = new int[] { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31,
30, 31 };
try {
if (argvs == null || argvs.length < 2) {
System.out
.println("pls input year parameter and month parameter.");
System.exit(0);
} else {
year = Integer.parseInt(argvs[0]);
month = Integer.parseInt(argvs[1]);
}
if (year % 400 == 0) {
monthdays = monthdays2;
} else if (year % 100 == 0) {
monthdays = monthdays1;
} else if (year % 4 == 0) {
monthdays = monthdays2;
} else {
monthdays = monthdays1;
}
} catch (Exception e) {
System.exit(-1);
}
if (monthdays == null) {
System.out.println("System error.");
} else {
System.out.println("The month days is " + monthdays[month - 1]);
}
System.out.println("bye!");
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
Baymax_lee
2018-04-17
知道答主
回答量:2
采纳率:0%
帮助的人:1630
展开全部
import java.util.*;
public class Question_6 {
public static void main(String[] args) {
// TODO 自动生成的方法存根
String Mon[]={"January","February","March","April","May","Jane","July","August",
"September","October","November","December"};
Scanner scanner = new Scanner(System.in);
System.out.println("Input year:");
int year = scanner.nextInt();
System.out.println("Input the month:");
int month = scanner.nextInt();
int day = 0;
switch(month)
{
case 1:;case 3:;case 5:;case 7:;case 8:;case 10:;case 12:day = 31;break;
case 4:;case 6:;case 9:;case 11:day = 30;break;
case 2:day = year % 4 == 0? 29: 28;break;
default:break;
}
//Integer mon = new Integer(month);
//Strig mon1 = mon.toString();
//month = String.valueOf(month);
System.out.println(month+","+year +" has "+day+" days ");
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式