Computer Applications
Choose the statement which is equivalent to the given:
if(a>b)
System.out.println("Honest");
else
System.out.println("Sincere");
a>b? System.out.println("Honest"):System.out.println("Sincere");System.out.println(a>b? "Honest":"Sincere");a>b? "Honest": "Sincere";a>b: "Honest"? "Sincere";
Java Conditional Stmts
2 Likes
Answer
System.out.println(a>b? "Honest":"Sincere");
Reason — The ternary operator condition ? value1 : value2 is used to select one of two values based on a condition. The above if-else statement can be rewritten using the ternary operator inside the println() method as: System.out.println(a > b ? "Honest" : "Sincere");. This statement prints "Honest" if a > b, otherwise it prints "Sincere".
Answered By
1 Like
Related Questions
The output of the statement
Math.ceil.(89.9) + Math.floor(90.5)is:- 0.0
- 180
- 180.0
- 180.4
The output of the statement of
"TIGER".indexOf('G')is:- 3
- 2
- -1
- 0
The two Java statement are used to check for the equality of the strings "COP" and "cop" are as follows:
"COP".equals("cop") "COP".equalsIgnoreCase("cop")The output of the above statements is:
- false, true
- true, false
- false, false
- true, true
The output of the java statement
"SOLDIER".compareTo("SOLUTE");is- -4
- -17
- 17
- 0