gpt4 book ai didi

java - 打印数组并避免空值时出现运算符(operator)错误

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

我试图从数组中打印出详细信息,但避免打印出空值,这是我的简短代码,任何人都可以明白为什么我收到错误“!运算符不能应用于小说”和“!运算符不能应用于非小说类”

case 2:
for (int i=0; i<5; i++){
if (!fictionArray[i] = null){
System.out.println(fictionArray);
}
if (!nonfictionArray[i] = null){
System.out.println(nonfictionArray);
}
}

break;

最佳答案

您想要fictionArray[i] != null= 是赋值运算符。 ! 是逻辑not 运算符。它仅适用于 boolean 表达式。

关于java - 打印数组并避免空值时出现运算符(operator)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20708341/

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