Site icon

Program to check given input number is even or odd in java (example)

What are even & odd numbers ?

Program: check given number is even or odd in java

package org.learn;

import java.util.Scanner;

public class DemoEvenOdd {

	public static boolean checkEvenOdd(int number) {
		if (number % 2 == 0)
			return true;
		else
			return false;
	}

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			System.out.printf("Enter input number : ");
			int inputNumber = scanner.nextInt();
			System.out.printf("Is even: %b", checkEvenOdd(inputNumber));
		}
	}
}

Output: check given number is even or odd in java

Enter input number : 5
Is even number : false

Enter input number : 6
Is even number : true

Enter input number : 25
Is even number : false
Exit mobile version