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;
int a=5, b=10;
int x = (a>b)>true:false;
Java Conditional Stmts
5 Likes
Answer
- Ternary operator is written incorrectly.
- 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
Rewrite the following statement using if else:
int max=215, min=323; String str= (max>min) ? "Max is greater than Min" : "Min is Greater than Max";
What will be the value of 'n' after the execution of the code given below?
int x=2, m=1, c=-1; int n = x + c; n = n - c + x; System.out.println(n);
Find the error in the given statement:
int x = (a => b) ? "a" : "b";
Write an if statement to find the smallest of the three given integers using the min() method of the Math class.