`java (0 % 2 != 0) == false`

后端 未结 6 997
闹比i
闹比i 2021-01-18 04:55

The part I keep getting stuck on is boolean(0 % 2 !=0) == false. I mean if 2 goes into 0, 0 times then the remainder would be 2, and 2 does not equal 0. S

6条回答
  •  广开言路
    2021-01-18 05:22

    There are two steps:

    • 0 % 2 evaluates to 0.

    • 0 != 0 evaluates to false.

    To elaborate on the first step, the JLS defines the % operator like so:

    The binary % operator is said to yield the remainder of its operands from an implied division; the left-hand operand is the dividend and the right-hand operand is the divisor.

    The remainder of dividing 0 by 2 is 0 and not 2 as you seem to think.

提交回复
热议问题