否则,如果发生错误-Java'('预期-参加在线课程。为在线测验编写了一些代码,并且系统接受了该代码。第二个测验问题非常相似。代码将无法运行并且不会肯定是错的。语法结构似乎与第一个问题的答案相似。我缺少什么?Java爱好者新手...
package com.JonEKreski;
public class Main {
public static void main(String[] args) {
shouldWakeUp(false, -1);
System.out.println("Dog is barking = " + barking);
}
public static boolean shouldWakeUp(boolean barking, int hourOfDay) {
if ((hourOfDay < 0) || (hourOfDay > 23)) {
barking = false;
} else if {
((hourOfDay < 8) || (hourOfDay > 22));
barking = true;
} else {
barking = false;
}
return barking;
}
}
答案 0 :(得分:0)
更正,否则应该
else if ((hourOfDay < 8) || (hourOfDay > 22)){
barking = true;
}
答案 1 :(得分:0)
您需要更改此内容
} else if {
((hourOfDay < 8) || (hourOfDay > 22));
barking = true;
} else {
...
与此:
} else if ((hourOfDay < 8) || (hourOfDay > 22)) {
barking = true;
} else {
...
答案 2 :(得分:0)
问题出在第9行。正确的代码:
public static void main(String[] args) {
shouldWakeUp(false, -1);
System.out.println("Dog is barking = " + barking);
}
public static boolean shouldWakeUp(boolean barking, int hourOfDay) {
if ((hourOfDay < 0) || (hourOfDay > 23)) {
barking = false;
} else if ((hourOfDay < 8) || (hourOfDay > 22)) {
barking = true;
} else {
barking = false;
}
return barking;
}