if-else to ternary operator – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  

Login
[lwa]



Exam Questions-ICSE2016-03E #JAVA#4244    siteicon   siteicon  

Problem Statement - if-else to ternary operator

Rewrite the following using ternary operator :
if(x%2 == 0)
System.out.print(“EVEN”);
else
System.out.print(“ODD”);

Solution

TC++ #4244

System.out.print((x%2 == 0) ? “EVEN”:”ODD”);


Share

sunmitra| Created: 31-Mar-2018 | Updated: 16-Apr-2019|ICSE2016






Back