Computer Applications

What is the output of the code snippet given below?

int lives = 5;
System.out.print(lives--);
System.out.print(lives);
  1. 4 3
  2. 5 4
  3. 5 3
  4. 4 4

Java

Java Operators

5 Likes

Answer

5 4

Reason — In System.out.print(lives--), the post-decrement operator (lives--) prints the current value of lives (which is 5) first, then decreases it to 4. The next System.out.print(lives) prints the updated value 4.

Answered By

2 Likes


Related Questions