codescracker


java

Java Program to Check Even or Odd



« Previous Program Next Program »


Check Even or Odd

To check whether the input number is an even number or an odd number in Java programming, you have to ask to the user to enter the number, now if number is divisible by 2 (it will be even number) and if the number is not divisible by 2 (it will be an odd number)

Java Programming Code to Check Even or Odd

Following Java Program ask to the user to enter a number, to check and display whether the entered number is even or odd:

/* Java Program Example - Check Even or Odd */
		
import java.util.Scanner;

public class JavaProgram
{
    public static void main(String args[])
    {
        int num;
        Scanner scan = new Scanner(System.in);
		
        System.out.print("Enter a Number : ");
        num = scan.nextInt();
		
        if(num%2 == 0)
        {
            System.out.print("This is an Even Number");
        }
        else
        {
            System.out.print("This is an Odd Number");
        }
    }
}

When the above Java Program is compile and executed, it will produce the following output. Above Java Programming Example Output (for even):

Java Program check number is even or odd

Above Java Programming Example Output (for odd):

check even odd in java

Same Program in Other Languages

You may also like to learn and practice the same program in other popular programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test