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

Here 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.

If the remainder of the modulus operator 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

Example : 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


Conclusion

That’s it guys. This is all about java program to check if a given number is odd or even. I hope you guys have understood the concept.

You can subscribe to my blog flower brackets if you haven’t already.

Do share this post if you like.

Related Posts