Home Java Program Examples Java Program to Check Whether a Number is Even or Odd

Java Program to Check Whether a Number is Even or Odd

by anupmaurya
1 minutes read

In order to check the number Whether a Number is Even or Odd, we have divided the number by 2 if it does not leave any remainder, the number is even otherwise number is odd.

Let’s have a look how we can implement this help of a java program.

import java.util.Scanner;

public class EvenOdd {

    public static void main(String[] args) {

        Scanner reader = new Scanner(System.in);

        System.out.print("Enter a number: ");
        int num = reader.nextInt();

        if(num % 2 == 0)
            System.out.println(num + " is even");
        else
            System.out.println(num + " is odd");
    }
}

What You get as Output , After running the program

Enter a number:25
25 is odd

Happy Programming 🙂

You may also like

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.