第四章第十七题(一个月的天数)(Days of a month)

*4.17(一个月的天数)编写一个程序,提示用户输入一个年份和一个月份名称的前三个字母(第一个字母使用大写形式),显示该月中的天数。如果输入的月份是非法的,显示一条出错信息。

下面是一个运行示例:
Enter a year: 2001
Enter a month: Jan
Jan 2001 has 31 days
Enter a year: 2016
Enter a month: jan
jan is not a correct month name

*4.17(Days of a month) Write a program that prompts the user to enter the year and the first three letters of a month name (with the first letter in uppercase) and displays the number of days in the month. If the input for month is incorrect, display a message as presented in the following sample runs:

Enter a year: 2001
Enter a month: Jan
Jan 2001 has 31 days
Enter a year: 2016
Enter a month: jan
jan is not a correct month name

下面是参考答案代码:

import java.util.*;

public class DaysOfMonthQuestion17 {
   
	public static void main(String[] args) {
   
		int year;
		String month;

		Scanner input = new Scanner(System.in);
		System.out.print("Enter a year:");
		year = input.nextInt();

		System.out.print("Enter a month:");
		month = input.nex
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值