gpt4 book ai didi

java - 我的程序不检查 else-if 语句

转载 作者:行者123 更新时间:2023-12-03 01:55:15 24 4
gpt4 key购买 nike

我对编码还是新手,所以请耐心等待。我的程序总是检查 if 语句中发生了什么,并且即使值为 false 也不会转到 else-if 语句。那么,为什么会发生这种情况呢?任何帮助将不胜感激。

for (int i = 0; i <= time; i++) { System.out.println("Clock loop = " + i);

for (int j = 0; j < cashierArr.length; j++) {
System.out.println("CashierArr at " + j + " is busy? "
+ cashierArr[j].busy);
System.out.println(j);

if (cashierArr[j].busy = true) {

cashierArr[j].serveTime -= 1;
System.out.println("Serve time = "
+ cashierArr[j].serveTime);
System.out.println("In busy");

} else if (cashierArr[j].busy = false) {


Customer tempCust = (Customer) queue.poll();


cashierArr[j].serveTime = tempCust.serviceTime;
System.out
.println("serveTime = " + cashierArr[j].serveTime);
cashierArr[j].busy = true;

System.out.println("In not busy");
}

}

最佳答案

请执行以下操作,

if (cashierArr[j].busy ==  true) { // == is comparison operator, while = is assign

you have used only single assignment which will actually assign the value to true means it's always remains true

if (cashierArr[j].busy =  true)

关于java - 我的程序不检查 else-if 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36187661/

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