Java Program to check a number is even or odd


In this program, You will learn how to check a number is even or odd in Java.


if (number % 2 == 0) { true } else { false }


Example: How to check a number is even or odd in Java

Run it Now
import java.util.Scanner;

class Main {
    public static void main(String args[]) {

        int a;
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter a Number :");
        a = sc.nextInt();

        if (a % 2 == 0) {
            System.out.println("\nNumber is Even :" + a);
        } else {
            System.out.println("\nNumber is Odd :" + a);
        }

    }
}

Output:

Enter a Number :12
Number is Even :12