Multiple choice technology programming languages

The modulus operator (%) in Java can be used only with variables of integer type.

  1. True

  2. False

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The modulus operator (%) in Java works with both integer AND floating-point types. It returns the remainder of division. For integers: 5 % 3 = 2. For floats: 5.5 % 2.0 = 1.5. The statement that it works 'only' with integers is false.

AI explanation

To answer this question, you need to understand the concept of the modulus operator (%) in Java.

The modulus operator (%) in Java calculates the remainder of dividing one number by another. It can be used with variables of integer type, but it can also be used with variables of floating-point types, such as float or double.

Therefore, the statement that the modulus operator (%) in Java can be used only with variables of integer type is incorrect.

Option A) True - This option is incorrect because the modulus operator (%) in Java can be used with variables of floating-point types as well. Option B) False - This option is correct because the modulus operator (%) in Java can be used with variables of both integer and floating-point types.

The correct answer is B) False. This option is correct because the modulus operator (%) in Java can be used with variables of integer and floating-point types.