Question: What will be the output for the following Java programming. Include explanation in your answer. public class Exception _ NegativeNumber { public static void main

What will be the output for the following Java programming. Include explanation in your answer.
public class Exception_NegativeNumber {
public static void main(String[] args){
int n =25;
tryNumber(n);
n =-10;
tryNumber(n);
}
public static void tryNumber(int n){
try {
checkPositiveNumber(n);
System.out.println(n +" is positive.");
} catch (IllegalArgumentException e){
System.out.println("Error: "+ e.getMessage());
}
}
public static void checkPositiveNumber(int number){
if (number <0){
throw new IllegalArgumentException(number +" is negative.");
}
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!