发布网友 发布时间:2022-04-30 10:23
共2个回答
热心网友 时间:2022-06-21 03:17
Scanner in=new Scanner(System.in);热心网友 时间:2022-06-21 03:17
付费内容限时免费查看回答你好,亲,比如:import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int[] days = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int month = -1;
while(true) {
try {
System.out.print("请输入月份:");
month = scanner.nextInt();
if(month >= 1 && month <= 12) {
break;
}
System.out.println("** 请输入正确的月份 **");
} catch (Exception e) {
System.out.println("** 格式错误!请输入数字 **");
scanner.next();
}
}
System.out.println(month + " 月份有:" + days[month - 1] + " 天");
}
}