这段java代码有什么问题?

时间:2014-07-19 17:58:21

标签: java

如果有人能在这段代码中找到错误,它会对我有所帮助。 我正在使用Eclipse,我正在尝试制作一个只需按一下按钮即可发出单词/句子的程序。如果您需要更多信息,请询问。

错误:“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 " };

1 个答案:

答案 0 :(得分:5)

似乎boverallboolean数组。试试这个:

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 是整数,特别是0false不同。< / p>