How to Check If a Number Is Even in Java


In this example we will show how to check if a number is even in Java.

Source Code

package com.beginner.examples;

public class Even {

  public static void main(String[] args){
    int a = 13;
    // check if the number is even or odd
    if(a%2 == 0) {
      System.out.println(a + " is an even number.");
    } else {
      System.out.println(a + " is an odd number.");
    }
  }
}

Output:

13 is an odd number.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments