【发布时间】:2022-01-21 11:38:38
【问题描述】:
private static int[] daysInMonth = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 };
我正在寻找一种方法,如果 year % 4 == 0 然后是 daysInMonth[1] = 29。
【问题讨论】:
-
if (year % 4 == 0) { daysInMonth[1] = 29; },如果这不是你想要的,那么你需要澄清你在问什么 -
1) 将数组定义为方法是什么意思? 2) 假设闰年由
year % 4 == 0定义是不完全正确的。 3) 为什么您需要更改数组中的值?这意味着对于其他“调用”,您必须检查/恢复 28 天。
标签: java arrays if-statement