ICSE Class 10 Computer Applications Question 12 of 43

Conditional Constructs in Java — Question 12

Back to all questions
12
Question

Question 12

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

int a=5, b=10;
int x = (a>b)>true:false;
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;