Normal Method
[js theme=”” group=”” tab=”” highlight=””]
public class even_odd
{
public static void main(int n)
{
if(n%2==0) //Checking if remainder is zero
System.out.println(“The number is even”);
else //else statement
System.out.println(“The number is odd.”);
}//end of main
}//end of class
[/js]
Using Ternary Operators
[js theme=”” group=”” tab=”” highlight=””]
public class ternary_even_odd
{
public static void main(int n)
{
System.out.println((n%2==0)?”Even”:”Odd”);
}
}
[/js]
Write a program to input a number 'N' and print whether the number is Even or Odd. Use Ternary Operators
Programming