KnowledgeBoat Logo

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");
  1. Both values are equal
  2. Incorrect use of the == operator
  3. Values are not equal
  4. 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