Java Program to Check Even or Odd Number

Here you will get java program to check even or odd number.

How to check?

If number is completely divisible by 2 then it is even otherwise odd.

In our program we will find the remainder of number by dividing it by 2 using modulus (%) operator. If remainder is 0 then number is even else odd.

Java Program to Check Even or Odd Number

import java.util.Scanner;

public class JavaEvenOdd {
	public static void main(String...s){
		int n;
		Scanner sc = new Scanner(System.in);
		
		System.out.println("Enter a number:");
		n = sc.nextInt();
		
		if(n%2 == 0){
			System.out.println("even number");
		}
		else{
			System.out.println("odd number");
		}
	}
}

 

Output

Enter a number:
4
even number

Leave a Comment

Your email address will not be published. Required fields are marked *