Java program to find even or odd

Hey guys!! Welcome to flower brackets blog. Today you will learn and execute java program to find even or odd.

java program to find even or odd

In the below java program to check if a given integer is odd or even, modulus operator is used. User enters a number as input.

This input number is divided by 2. If the remainder is equal to 0 then the number entered is even number else the number entered is odd number.

Also read – even odd program in java using array

Java program to find even or odd

import java.util.Scanner;

public class EvenOdd
{
   public static void main(String[] args)
   {
      int a;
      System.out.println("Please enter a number to check even or odd : ");
      Scanner sc = new Scanner(System.in);
      a = sc.nextInt();

      if(a % 2 == 0)
      {
         System.out.println("Entered number is an even number");
      }
      else
      {
         System.out.println("Entered number is an odd number");
      }
   }
}

Output:

Please enter a number to check even or odd : 5
Entered number is an odd number


Related Posts