Even or Odd Number Example Program in Java Programming Language

Here we have the Java Programming Language Example Program to Check for Even or Odd Number.

When you divide a number by 2 if you get the remainder as 0 then that number is said to be Even Number. If the remainder is a Non Zero value then it is an Odd Number.

Here we are using the modulus operator available in Java programming language. It is denoted by using % ( percentage ) symbol.

Java Program to Check for Even or Odd Number

 1 package exampleProgram;
 2 
 3 import java.util.Scanner;
 4 
 5 public class EvenOdd {
 6 
 7         public static void main(String[] args) {
 8             
 9             int number,remainder;
10             System.out.println("Pls Enter an Integer Number");
11             Scanner scan = new Scanner(System.in);
12             number = scan.nextInt();
13             scan.close();
14             
15             remainder = number % 2;
16             
17             if( remainder == 0 )
18                 System.out.println(number+" is an Even Number");
19             else
20                 System.out.println(number+" is an Odd Number");
21             
22         } 
23 }

For Explanation Checkout this Video