Expressions and Assignment Statements

AP Computer Science A· difficulty 4/5

In Java, <code>-7 % 3</code> evaluates to

  • A

    2

  • B

    −1

    check_circle
  • C

    1

  • D

    −2

Explanation

Java's <code>%</code> follows the sign of the dividend: −7 = 3·(−2) + (−1), so result is −1.

Want 10 more like this — adaptive to your weak spots?

Related questions