错误:“if(this.boverall [a]!= 0){”,ERROR message“运算符!=未定义参数类型boolean,int”
public String sentenceOverall()
{
ArrayList<String> toBeUsed = new ArrayList();
for (int a = 0; a < this.soverall.length; a++) {
if (this.boverall[a] != 0) {
toBeUsed.add(this.soverall[a]);
}
}
if (toBeUsed.size() == 2)
{
int sentencePattern = rand.nextInt(10);
if (sentencePattern < 9)
{
String[] OverallOptions = { " The song is overall both ", " Overall, the song is both ", " This song, overall, is both ", " Your song is quite ", " I think that the song is ", " I believe that your song is both ", " Your song is without a doubt ", " In my point of view, this is ", " First of all, thank you for creating this song. This song is very ", " Judging from my position, this song is ", " Personally, I think that the song is ", " All things taken together, I would say that this song is " };
答案 0 :(得分:5)
似乎boverall
是boolean
数组。试试这个:
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
不同。< / p>