volume_mute

What is the result of print statement in this Java program (-=)?

publish date2020/09/05 02:29:00 GMT+10

volume_mute
public class AssShortcutExample {
   public static void main(String args[]) {
      int num1 = 10;
      int num2 = 20;

      num2 -= num1;
      System.out.println("= Result: "+num2);
}
}
Missing Word

Correct Answer

10

Explanation

num2 -= num1 is a shortcut assignment operator to subtract num1 from num2 and assign the result to num2

num2 = num2 - num1 --> num2 = 20 - 10

num2 = 10


Quizzes you can take where this question appears