Rewrite the following using ternary operator:

if (x%2 == 0)
System.out.print("EVEN");
else
System.out.print("ODD");

Views 12

Answer:


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

Related Articles:

This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of Java Programming Language, click the links and dive deeper into this subject.

Join Our telegram group to ask Questions

Click below button to join our groups.