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.

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("Number is even:" + a);
        } else {
            System.out.println("Number is odd:" + a);
        }

    }
}

Output:

Enter a number:6
Number is even:6