Java Program to Find whether a number is Even or Odd

In this program we will write a Java Even Odd Program Code to find whether a number entered is Even or Odd. We will be using the If-Else conditional control statements to check if the number entered is Even or Odd. in the condition we will be using the Modulo Operator as follows –

Java Even Odd Program Code Example –
class CheckEvenOdd
{
  public static void main(String args[])
  {
    int num;
    System.out.println("Enter an Integer number:");

    //The input provided by user is stored in num
    Scanner input = new Scanner(System.in);
    num = input.nextInt();

    /* If number is divisible by 2 then it's an even number
     * else odd number*/
    if ( num % 2 == 0 )
        System.out.println("Entered number is even");
     else
        System.out.println("Entered number is odd");
  }
}
Output
Enter an Integer number:
78
Entered number is even
Watch it on YouTube

Leave a Reply

Your email address will not be published. Required fields are marked *