【发布时间】:2018-10-15 12:40:14
【问题描述】:
问题:当狗在吠叫时,在早上 8 点或晚上 22 点之前,返回 true,否则返回 false。
我的代码:
public class Barkingdog {
public boolean bark(boolean barking, int hourofDay) {
if (barking) {
if (hourofDay >= 0 && hourofDay <= 8) {
return true;
} else if (hourofDay >= 22 && hourofDay < 24) {
return true;
} else {
return false;
}
} else {
return false;
}
}
}
尝试测试我的代码:
package com.company;
public class Main {
public static boolean main(String[] args) {
// write your code here
System.out.println(public boolean bark (true, 4););
}
}
【问题讨论】:
-
尝试使用
System.out.println(bark(true, 4));
标签: java error-handling expression