KnowledgeBoat Logo
|

Computer Applications

Mention the output of this code snippet:

int lives = 5; 
    System.out.println(lives--); 
    System.out.println(lives);

Java Operators

1 Like

Answer

Output
5
4
Explanation
  1. The variable lives is initialized to 5.
  2. The statement System.out.println(lives--); first prints the current value of lives, which is 5, and then decreases the value of lives by 1 because lives-- is the postfix decrement operator.
  3. After this statement, the value of lives becomes 4.
  4. The next statement System.out.println(lives); prints the updated value of lives, which is 4.

Answered By

1 Like


Related Questions