package Experiment.Java.test8;
import java.util.Scanner;
//判断几月几天
public class Day {
public static void main(String[] args) {
Day day = new Day();
day.month();
}
public void month() {
int[] ints = {1, 3, 5, 7, 8, 10, 12};
int[] ints1 = {4, 6, 9, 11};
Scanner in = new Scanner(System.in);
System.out.println("输入年份");
int year = in.nextInt();
System.out.println("输入月份");
int num = in.nextInt();
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
if (num == 2) {
System.out.println(year+"是闰年,"+num+"月有"+"29天");
}
for (int i = 0; i < ints.length; i++) {
if (num == ints[i]) {
System.out.println("31天");
}
}
for (int i = 0; i < ints1.length; i++) {
if (num == ints1[i]) {
System.out.println("30天");
}
}
} else {
if (num == 2) {
System.out.println(year+"是平年,"+num+"月有"+"28天");
}
for (int i = 0; i < ints.length; i++) {
if (num == ints[i]) {
System.out.println("31天");
}
}
for (int i = 0; i < ints1.length; i++) {
if (num == ints1[i]) {
System.out.println("30天");
}
}
}
}
}
编写自定义方法,传递年份、月份,返回该月的天数。
最新推荐文章于 2022-09-05 19:55:40 发布