2014-07-19 197 views
-4

如果有人能夠發現此代碼中的錯誤,它將幫助我一噸。 我正在使用Eclipse,並且我正試圖製作一個程序,只需按一下按鈕即可吐出單詞/句子。如果您需要更多信息,請詢問。這段java代碼有什麼問題?

ERROR: 「如果(this.boverall [α]!= 0){」,ERROR消息 「操作員=未定義的參數類型(一個或多個)的布爾,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

什麼是'boverall'數組? – BitNinja

+0

說實話,我不知道。我發現了一種我想上網的程序,我正在編輯它,因此它吐出了我想要的單詞,但在此之前,我需要修復所有代碼錯誤。 – user3856445

+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

+0

非常感謝你,我還是新手,你解決了我的所有問題。<3謝謝你的每一個人 – user3856445

+0

這看起來與OP想要的完全相反。他們正在測試它是否爲非零,通常相當於真。 – McLovin

+0

注意詳細說明,就好像(!this.boverall [a])似乎不起作用 – user3856445