How does returning an || statement work in java?

前端 未结 7 645
北荒
北荒 2021-01-29 16:04

I\'m new to programming so I have been working through the exercises at CodingBat.com. In the Recursion-2 section, there is a problem I wasn\'t able to solve (recursively) so I

7条回答
  •  伪装坚强ぢ
    2021-01-29 16:43

    Every recursive function needs an ending point. Yours is:

    if (start >= nums.length) return sum1 == sum2;
    

    It will return true or false, depending on (sum1 == sum2).

    Refering to the statement:

    else {return (A || B); }
    

    It will get into the first clause, until its return TRUE or FALSE. If it returns TRUE, it is the end of the line. Else, it will evaluate the second clause and return the match (A || B).

    (TRUE || TRUE) -> TRUE
    (TRUE || FALSE) -> TRUE
    (FALSE || TRUE) -> TRUE
    (FALSE || FALSE) -> FALSE
    

提交回复
热议问题