你是一个比较String
(answer1
)到Integer
(correctAnswer
).那是比较苹果和橘子,它们永远不会相同.
您需要转换String
为int
:
Integer.parseInt(answer1)
如果answer1
无法解析为整数,则可能会失败; 或转换int
为String
:
Integer.toString(correctAnswer)
然后比较它们:
Integer.parseInt(answer1) == correctAnswer // You can use == because int is primitive. or answer1.equals(Integer.toString(correctAnswer))