Computer Applications
Predict the output of the following code snippet:
int a = 1;
int b = 2;
if (a == b)
System.out.println("Both values are equal");
else
System.out.println("Values are not equal");
- Both values are equal
- Incorrect use of the == operator
- Values are not equal
- No output
Java Conditional Stmts
5 Likes
Answer
Values are not equal
Reason — Since the values of a and b are not equal, the condition (a == b)
is false. Thus, the else block is executed and "Values are not equal" is printed.
Answered By
3 Likes
Related Questions
Which of the following is/are principle(s) of Object Oriented Programming?
- Encapsulation
- Abstraction
- Inheritance
- All of these
If a = 8 and b = 4, the value of
a % = b
is- 2
- 0
- 4
- 8
Which of the following is mandatory in the switch statement?
- break
- continue
- case
- default
Which of the following is not a valid method of the Scanner class?
- next( )
- nextInt( )
- nextLong( )
- nextNumber( )