Unreachable statement?

前端 未结 2 1903
遇见更好的自我
遇见更好的自我 2020-12-22 12:18

Here is my coding: For some reason, at the very end, when I\'m trying to return winscounter and losscounter, it says unreachable statement but not for the tiescounter. I can

相关标签:
2条回答
  • 2020-12-22 13:10

    A function can only return one value. As soon as return(tiescounter); is executed the function exits. If you want to return all three values you will have to wrap them in a class.

    By the way return(tiescounter); can be written as return tiescounter; Parenthesis around return values is not required. Both statements will have the same result.

    0 讨论(0)
  • 2020-12-22 13:11

    You cannot return 3 different variables from one method, all at the same time. In this case, the return(tiescounter); always executes, terminating the method then and there. Hence the next 2 lines become unreachable.

    Declare determineOutcome() method as void i.e. public static void determineOutcome(), and remove all return statements inside it. Your program will work.

    0 讨论(0)
提交回复
热议问题