Write a Java program to create a method that takes an integer as a parameter and throws an exception if the number is odd.

Source Code:

public class OddCheck {
public static void checkNumber(int n) {
if(n % 2 != 0) {
throw new IllegalArgumentException(“Number is odd”);
}
System.out.println(“Number is even”);
}

public static void main(String[] args) {
try {
checkNumber(5);
} catch(Exception e) {
System.out.println(e.getMessage());
}
}
}

Output: