String variable may not have been initialized (error diects to line 34)

前端 未结 4 551
太阳男子
太阳男子 2021-01-26 00:59

I\'ve been trying to get the string initialize, but to no avail. I have tried all of the solutions I have come across and I am not sure whether it is because of my ineptness or

4条回答
  •  囚心锁ツ
    2021-01-26 01:58

    The compilator see you have String computer. He can also see that this computer is initialized for answer 1 or 2 or 3. But because it cant read logic, it does not know anything about if answer can be or cannot be lower or higher so it is assuming the worst possibility - that computer will not be initialized.

    Just change your up line to

    String computer = "";
    

    and it should be fine.

提交回复
热议问题