KnowledgeBoat Logo

Computer Applications

Find the error, if any, in the following code. Write the correct statement.

int a=5, b=10;
int x = (a>b)>true:false;

Java Conditional Stmts

5 Likes

Answer

  1. Ternary operator is written incorrectly.
  2. Type of x should be boolean.
Corrected Statement

int a=5, b=10;
boolean x = (a>b) ? true:false;

Answered By

2 Likes


Related Questions