Main menu

You are here

Java program to find odd or even

This java program finds if a number is odd or even. If the number is divisible by 2 then it will be even, otherwise it is odd. We use modulus operator to find remainder in our program.

Java programming source code

importjava.util.Scanner;class OddOrEven
{publicstaticvoid main(String args[]){int x;System.out.println("Enter an integer to check if it is odd or even ");
Scanner in =new Scanner(System.in);
x = in.nextInt();if( x %2==0)System.out.println("You entered an even number.");elseSystem.out.println("You entered an odd number.");}}