Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

Mastering Java: The Ultimate Quiz for 'Thinking in Java'. Dive deep into Java with multiple-choice questions. Challenge yourself with quiz questions designed to test and improve your understanding of the 'Thinking in Java' book. Get ready for your exam!

Practice this question and more.


In the expression 'j %= k;', given that j and k are integers, what does this operation do?

  1. Divides j by k and assigns the remainder to j

  2. Multiplies j and k and assigns the result to j

  3. Subtracts k from j and assigns the result to j

  4. Adds j and k and assigns the result to j

The correct answer is: Divides j by k and assigns the remainder to j

In this expression, the '%=' operator is known as the modulus operator. This operation returns the remainder of dividing j by k, and then assigns that value to j. Therefore, option A is the correct answer. Option B is incorrect because the multiplication operator is '*', not '%='. Option C is incorrect because the subtraction operator is '-', not '%='. Option D is incorrect because the addition operator is '+', not '%='.