Rewrite the Following Using Ternary Operator: If (X%2 == O) System.Out.Print(“Even”); Else System.Out.Print(“Odd”);
Advertisements
Question
Rewrite the following using ternary operator:
if (x%2 == o)
System.out.print(“EVEN”);
else
System.out.print(“ODD”);
Answer in Brief
Short/Brief Note
Advertisements
Solution
String k;
k = x%2 == 0 ? “EVEN” : “ODD”;
System.out.print(k);
shaalaa.com
Introduction of Operators in Java
Is there an error in this question or solution?
