2 回答
TA贡献1821条经验 获得超6个赞
参数不是必需的 - 您要求在方法中输入。像这样声明你的方法:
public static void daysInMonth ()
或者完全去掉输入,调用方法时输入参数。像这样:
public static void main(String[] args){
daysInMonth(3);
}
public static void daysInMonth (int month){
if (month == 4 || month == 6 || month == 9 || month == 11) {
System.out.println("30 days");
} else if ( month == 2){
System.out.println("28 days");
} else {
System.out.println("31 days");
}
}
TA贡献1818条经验 获得超3个赞
参数不是必需的 - 您要求在方法中输入。像这样声明你的方法:
public static void daysInMonth ()
或者完全去掉输入,调用方法时输入参数。像这样:
public static void main(String[] args){
daysInMonth(3);
}
public static void daysInMonth (int month){
if (month == 4 || month == 6 || month == 9 || month == 11) {
System.out.println("30 days");
} else if ( month == 2){
System.out.println("28 days");
} else {
System.out.println("31 days");
}
}
添加回答
举报