洛谷分支结构JavaP5716
题目:输入年份和月份,输出这一年的这一月有多少天。需要考虑闰年。
需要考虑闰年 二月份 闰年29天 平年28天
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int years = input.nextInt();
int month = input.nextInt();
int c1[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; //平年
if ((years % 400 == 0) || ((years % 4 == 0) && (years % 100 != 0)))
c1[2] = 29; //闰年2月份天数
System.out.println(c1[month]);
}
}