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 »


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.