【发布时间】:2017-11-20 21:39:03
【问题描述】:
索引 0 必须从队列中删除。你回答 总是在索引 0 上找到的对话上。队列中的所有其他呼叫必须“向前移动”一步,以便索引 1 现在应该获得索引 0,依此类推。尝试了这种方法和许多其他方法,但无法正常工作。
public static void answerCall() {
for (int i = 0; i < customerList.length-1; i++) {
if (customerList[i] != null && customerList[i + 1] == null) {
customerList[i] = null;
counter--;
} else if (customerList[i] != null && customerList[i + 1] != null) {
customerList[i] = customerList[i + 1];
customerList[i + 1] = null;
counter--;
}
}
}
}
【问题讨论】:
-
这就是为什么你应该使用集合而不是数组。
-
我知道但我必须使用数组...
-
为什么所有
if声明?只有循环内的语句应该是customerList[i] = customerList[i + 1];语句。然后在你将最后一个值设置为null的循环之后。