Even Odd Program in Java using Conditional Operator

We will create an even odd program in java using conditional operator.

Program : Write a Program to input any number and check number is Even or Odd.

// Program to check Number is Even or Odd using Conditional Operator.
import java.util.*;
class EvenOdd
	public static void main(String ar[])
		Scanner sc = new Scanner(System.in);
		int num;
		String str;
		System.out.print("Enter a Number: ");
		num = sc.nextInt();
		str = (num%2 == 0) ? "Even" : "Odd";
		System.out.println("The Number is " + str);
Enter a Number: 4
The Number is Odd

Be the first to comment

Leave a Reply

Your email address will not be published.