Java Program to Check Whether a Number is Even or Odd

In this example, we are giving a program to check wheather a number is even or odd.


To check a number is even or odd:

  1. # To check a number is even or odd
  2. public class EvenOdd {
  3. public static void main(String[] args) {
  4. Scanner reader = new Scanner(System.in);
  5. System.out.print("Enter a number: " );
  6. int num = reader.nextInt();
  7. if(num % 2 == 0)
  8. System.out.println(num + " is even");
  9. else
  10. System.out.println(num + " is odd");
  11. }
  12. }

Output:

Enter a number: 20
20 is even