Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
这段java代码有什么问题?_Java - Fatal编程技术网

这段java代码有什么问题?

这段java代码有什么问题?,java,Java,如果有人能找到这段代码中的错误,那将对我大有帮助。 我正在使用Eclipse,我正在尝试制作一个只需按下一个按钮就能吐出单词/句子的程序。如果你需要更多的信息,尽管问 错误:“如果(this.boverall[a]!=0){”,错误消息“运算符!=对于参数类型boolean,int未定义” 公共字符串语句总体() { ArrayList toBeUsed=新的ArrayList(); for(int a=0;a

如果有人能找到这段代码中的错误,那将对我大有帮助。 我正在使用Eclipse,我正在尝试制作一个只需按下一个按钮就能吐出单词/句子的程序。如果你需要更多的信息,尽管问

错误:“如果(this.boverall[a]!=0){”,错误消息“运算符!=对于参数类型boolean,int未定义”

公共字符串语句总体()
{
ArrayList toBeUsed=新的ArrayList();
for(int a=0;a
似乎
boverall
是一个
布尔数组。请尝试以下方法:

if (this.boverall[a])
我是如何达到那种状态的?让我们看看,一步一步:

this.boverall[a] != 0     // this is wrong, can't compare int with boolean
this.boverall[a] != false // this is what you really meant to write
this.boverall[a] == true  // if it's not false, then it can only be true
this.boverall[a]          // equivalent to the above line, but shorter

记住,在Java中(与其他编程语言不同)一个
boolean
不是一个整数,特别是
0
false

什么是
boverall
数组?老实说,我不确定。我在网上找到了我想要的程序,我正在编辑它,这样它就可以吐出我想要的单词,但在我可以做之前,我需要修复所有的代码错误唯一的一段代码?在许多语言中,您可以使用
0
作为
false
的隐式符号,在java中,您必须编写
false
与布尔值进行比较。错误非常明显!您不能将运算符!=应用于布尔值和int。两者必须是同一类型。编译器说您无法将苹果与ora进行比较nges!非常感谢你,我还是个新手,你解决了我所有的问题。这似乎与OP想要的正好相反。他们正在测试它是否为非零,这通常相当于真。注意详细说明,好像(!this.boverall[a])似乎没有work@user3856445
错误,请删除它。我更新了相应的答案,直到似乎给了我相同的错误,我应该删除“!=0”,因为这会消除错误,但我不确定它是否会使整个代码不再工作
this.boverall[a] != 0     // this is wrong, can't compare int with boolean
this.boverall[a] != false // this is what you really meant to write
this.boverall[a] == true  // if it's not false, then it can only be true
this.boverall[a]          // equivalent to the above line, but shorter