Complete the following Java program by typing in the missing statements in the space provided. This program inputs a value/s from user, and displays the result of some operation. If the operation generated an exception / error, it is handled by the user defined exception class. The main method in the application class is declared to throw a user-defined exception which will take care of the exception.
import // for input from keyboard
public class MyExceptionApp {
public static void main( ) throwsMyDivByZeroException {
Scanner kb =
System.out.println("Enter two numbers for division : ");
double n1 = kb.nextDouble();
double n2 = kb.nextDouble();
try{
if( n2 == 0 )
throw
else
System.out.println("Answer = " + n1/n2);
}
catch ( e){
System.out.println("Exception caught : " + e);
System.out.println("Program terminated normally ... ");
// definition of MyDivByZeroException class
class MyDivByZeroException {
{ // default constructor is required
{ // a constructor with String argument is also required
System.out.println(msg);
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here