Java program to find odd or even

Java program to check if a number is odd or even: if a number is divisible by two then it is even, otherwise, it is odd. We use modulus operator to find remainder in our program. For an even number remainder will be zero when it is divided by two and will be one for an odd number.

Java program to find odd or even


import java.util.Scanner;

class OddOrEven
{
public static void 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("The number is even.");
else
System.out.println("The number is odd.");
}
}

Output:

Java program to find odd or even

Post a Comment