BEST SITE FOR WEB DEVELOPERS
Java programming language. Lessons for beginners

Ua

Java How To Find Even or Odd Numbers


Check Whether a Number is Even or Odd

Find out if a number is even or odd:

Example

int number = 5;

// Find out if the number above is even or odd
if (number % 2 == 0) {
  System.out.println(number + " is even.");
} else {
  System.out.println(number + " is odd.");
}
Try it Yourself »