Computer Applications
What is the output of the code snippet given below?
int lives = 5;
System.out.print(lives--);
System.out.print(lives);
- 4 3
- 5 4
- 5 3
- 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
What is the output of the following statement:
“MONOPOLY”.lastIndexOf(‘O’);- 1
- 3
- 2
- 5
Typecasting is often necessary when dealing with financial data. Identify the correct syntax to typecast a double to an int using the variables:
int amount; double valueINR- int amount = valueINR;
- int amount = Integer.parseInt (valueINR);
- int amount = (int) valueINR;
- int amount = int (valueINR);
What will be the output of the following statement?
String s = "JavaProgramming"; System.out.println(s.substring(4, 11).toUpperCase());- Programm
- PROGRAMM
- PROGRAM
- program
Which of the following access specifiers will make a member accessible only within its own class?
- public
- private
- protected
- default