The following code demonstrates how to Find Whether a Number is Odd or Even in Java.

At first, we accept the input number from the user with the help of an object of the Scanner class. After that using the if statement, we check whether the number is divisible by two or not.

import java.util.Scanner;
public class Exercise2
{
	public static void main(String[] args) {
		int n1;
		System.out.println("Enter a Number: ");
		Scanner scn=new Scanner(System.in);
		n1=scn.nextInt();
		if(n1%2==0)
			System.out.println(n1+" is Even");
		else
			System.out.println(n1+" is Odd");
	}
}

Output

A Program to Find Whether a Number is Odd or Even in Java

Further Reading

Java Practice Exercise

programmingempire

Princites