bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Java/Java How To's
Java•Java How To's

Java How To Find Even or Odd Numbers

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind Java How To Find Even or Odd Numbers?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

___ number = 5;
3Order

Put the learning moves in the order that makes the concept easiest to apply.

Explanation: The operator % gives the remainder when dividing a number.
Find out if a number is even or odd:
Check Whether a Number is Even or Odd

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.");
}

Explanation: The operator % gives the remainder when dividing a number. - If number % 2 equals 0 , the number divides evenly by 2, it is even. - Otherwise, it has a remainder, it is odd.

Previous

Java How To Swap Two Variables

Next

Java How To Reverse a Number