by Dinesh Thakur Category: Data Type

In the Following example OddorEvenNumbers use mod operator to check if the number is even or odd. If the number divided by 2 and the reminder is 0 then number is even, otherwise the number is odd.

Here is the java code for the program OddorEvenNumbers :


public class OddorEvenNumbers {
        public static void main(String[] args) {
                     int no = 0;  
                     System.out.print("Please enter a Number :");
        BufferedReader Buffer= new BufferedReader(new InputStreamReader(;
                         no = Integer.parseInt(Buffer.readLine());
                         if(no%2 == 0)
                                System.out.println(no + " is Even Number.");
                                System.out.println(no + " is Odd Number.");
                     catch(Exception e)
                                 System.out.println("Input Error : "+e);                       

number is even or odd



 Suppose, the value entered is say 217. It is assigned to the integer variable no. Now, no is divided by 2  (% returns remainder). Since 10 will be divided by 2 completely and remainder comes out to be o. Hence, we get the message" Number is even" on the screen. When we enter a value say 217, this time we get remainder as 1  and it will display the message "Number is odd" on the screen.

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Search Content