gpt4 book ai didi

java - 运算符||不能包含在 int 中?

转载 作者:行者123 更新时间:2023-11-29 08:23:38 24 4
gpt4 key购买 nike

public class shouldWakeUp {

public static boolean shouldWakeUp(boolean barking, int hourOfTheDay) {

if (barking) {
if (hourOfTheDay=8 || hourOfTheDay=7 || hourOfTheDay=6 || hourOfTheDay=5 || hourOfTheDay=4 || hourOfTheDay=3 || hourOfTheDay=2 || hourOfTheDay=1 || hourOfTheDay=23 || hourOfTheDay=00) {
return true;
} else {
return false;
}
if (hourOfTheDay < 0 || hourOfTheDay > 23)
return false;
}
}
}

我无法理解错误,它说:operator ||不能包含在 int 中。

最佳答案

使用此代码

public static boolean shouldWakeUp(boolean barking, int hourOfTheDay) {
if (barking) {
if (hourOfTheDay==8 || hourOfTheDay==7 || hourOfTheDay==6 || hourOfTheDay==5 || hourOfTheDay==4 || hourOfTheDay==3 || hourOfTheDay==2 || hourOfTheDay==1 || hourOfTheDay==23 || hourOfTheDay==00) {
return true;
} else {
return false;
}
if (hourOfTheDay < 0 || hourOfTheDay > 23)
return false;
}
}

为了比较,您必须使用 == 而不是 =

关于java - 运算符||不能包含在 int 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55334852/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com