Odd Or Even Example Java Program


Definition

A formal definition of an even number is that it is an integer of the form n = 2k, where k is an integer;[3] it can then be shown that an odd number is an integer of the form n = 2k + 1.

Odd Or Even Example Program

import java.util.Scanner;
class OddOrEven{
	public static void main(String args[]){
		int num;
		System.out.println("Enter a number: ");
		Scanner in = new Scanner(System.in);
		num = in.nextInt();
		if ( num % 2 == 0 ){
			System.out.println("The number you entered is an even number");
		}
		else{
         System.out.println("The number you entered is an odd number");
		}
	}
}

Sample Output

Output is:
Enter a number:
56
The number you entered is an even number