Even odd program in java using ternary operator

Hey guys!! Welcome to flower brackets blog. In this post let’s learn even odd program in java using ternary operator.

Even odd program in java using ternary operator

Let’s see java program to check whether a number is even or odd using ternary operator,

Also read – Even odd program in java using array

public class EvenOddTernary
{
public static void main(String[] args)
{
int num = 14;
boolean checkEven = num % 2 == 0 ? true:false;
if(checkEven)
{
System.out.println(num + " is even number.");
}
else
{
System.out.println(num + " is odd number.");
}
}
}

Output:

14 is even number.

Related Posts