• Tutorials
  • DSA
  • Data Science
  • Web Tech
  • Courses
November 04, 2022 |5.3K Views

Java Program to Check Whether Number is Even or Odd

Description
Discussion

In this video, we will see how to write a Java program to check whether a number is odd or even.

Check if the number is odd or even
 

Approaches:

1) Method 1:
Using modulus operator : Modulus operator gives the remainder which is obtained when divided by a certain number. So, if the remainder is 0 after dividing it by zero then it means it is even else it is odd.

2) Method 2:
Using bitwise operator: If bitwise and of 1 and any number is equal to 1 then that number is said to be odd else it is even. As a computer process numbers in the bitwise format only this operator works faster as compare to that of the modulus operator.

Java program to check if a given integer is odd or even:
https://www.geeksforgeeks.org/java-program-to-check-if-a-given-integer-is-odd-or-even/