public class DivideException {
public static void main(String[] args) {
division(100,4); // Line 1
division(100,0); // Line 2
System.out.println("Exit main().");
}
public static void division(int totalSum, int totalNumber) {
System.out.println("Computing Division.");
int average = totalSum/totalNumber;
System.out.println("Average : "+ average);
}
}
++++++++++++++++++++++++
An ArithmeticException is thrown at runtime when Line 11 is executed because integer division by 0 is an illegal operation. The “Exit main()” message is never reached in the main method
Output
Computing Division.
java.lang.ArithmeticException: / by zero
Average : 25
Computing Division.
at DivideException.division(DivideException.java:11)
at DivideException.main(DivideException.java:5)
Exception in thread “main”
public static void main(String[] args) {
division(100,4); // Line 1
division(100,0); // Line 2
System.out.println("Exit main().");
}
public static void division(int totalSum, int totalNumber) {
System.out.println("Computing Division.");
int average = totalSum/totalNumber;
System.out.println("Average : "+ average);
}
}
++++++++++++++++++++++++
An ArithmeticException is thrown at runtime when Line 11 is executed because integer division by 0 is an illegal operation. The “Exit main()” message is never reached in the main method
Output
Computing Division.
java.lang.ArithmeticException: / by zero
Average : 25
Computing Division.
at DivideException.division(DivideException.java:11)
at DivideException.main(DivideException.java:5)
Exception in thread “main”
No comments:
Post a Comment