Write a Java program that implements a function Check Even Odd that checks that a number input by user is even or odd
import java.util.Scanner;
public class App {
public static void main(String[] args) {
Scanner keyBoard = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = keyBoard.nextInt();
CheckEvenOdd(number);
keyBoard.close();
}
private static void CheckEvenOdd(int number) {
if (number % 2 == 0) {
System.out.println("The number " + number + " is even.");
} else {
System.out.println("The number " + number + " is odd.");
}
}
}
Comments
Leave a comment