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:
# To check a number is even or oddpublic 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");elseSystem.out.println(num + " is odd");}}
Output:
Enter a number: 20 20 is even