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 types (int, long, short, byte) AND floating-point types (float, double). For example, 5.5 % 2.1 equals 1.3. The statement claims it only works with integers, which is false.

AI explanation

To answer this question, you need to understand the modulus operator (%) in Java and the types of variables it can be used with.

The modulus operator (%) in Java calculates the remainder of one number divided by another. While it is commonly used with integer types, it can also be used with other data types such as floating-point numbers (e.g., double and float).

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

Let's go through each option to understand why it is correct or incorrect:

Option A) True - This option is incorrect because the modulus operator (%) in Java can be used with variables of other types, not just integer types.

Option B) False - This option is correct because the statement "The modulus operator (%) in Java can be used only with variables of integer type" is false.

The correct answer is B) False.