簡體   English   中英

While循環Java中的多個條件問題

[英]Problems with multiple conditions in while loop java

我在Java while循環中遇到多個條件問題。 我試圖把條件不等於null,但是android studio說&&不能應用於布爾值。 任何幫助表示贊賞!

我正在嘗試這樣做:

String question = null, answer = null, answerOne = null,
        answerTwo = null, answerThree = null, answerFour = null;

while (((question = reader.readLine()) != null)
        && ((answer = reader.readLine()) != null)
        && (answerOne = reader.readLine()) !null)
        && ((answerTwo = reader.readLine()) != null)
        && (anwserThree = reader.readLine()) != null)
        && ((anwserFour = reader.readLine()) != null)) {

    //reading some lines from resource file
    Question q = new Question(question, answer, answerOne, answerTwo,
            answerThree, answerFour);
        mQuestions.add(q);
}

您的條件不正確。 這包括缺少開頭括號(!運算符,其中!=運算符有意義,缺少結束括號) ,以及條件中2個變量的“ answer”拼寫錯誤。

更換

(answerOne = reader.readLine()) !null)

((answerOne = reader.readLine()) != null)  // Two ( at beginning; !=

更換

( anwserThree= reader.readLine()) != null)

((answerThree = reader.readLine()) != null) // Two ( at beginning; spelling

更換

( (anwserFour= reader.readLine()) != null)

((answerFour= reader.readLine()) != null))  // Spelling; Two ) at end

您在while條件的一部分中遇到了錯字:

(answerOne = reader.readLine()) !null)

應該:

(answerOne = reader.readLine()) != null)

也許可以解決您的問題?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM