MCQ Single Best Answer Easy

QWhat is the value of y after the expression y *= 3 is executed in Java?

ID: #20129 Arithmetic Operators in Java 90 views
Question Info
#20129Q ID
EasyDifficulty
Arithmetic Operators in JavaTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A y is multiplied by 3
  • B y is divided by 3
  • C y is decremented by 3
  • D y is incremented by 3
Correct Answer: Option A

Explanation

The compound assignment operator (*=) in Java is used to multiply the right operand by the left operand and assign the result to the left operand. In this case, y *= 3 is equivalent to y = y * 3.


public class CompoundAssignmentExample {
    public static void main(String[] args) {
        // Define the initial value of y
        int y = 5;

        // Use the compound assignment with multiplication (y *= 3)
        y *= 3;

        // Display the result
        System.out.println("Value of y after y *= 3: " + y);
    }
}

When you run this program, it will output:


Value of y after y *= 3: 15

Share This Question

Challenge a friend or share with your study group.