Write a program that reads integers userNum and divNum as input, and output the quotient (userNum divided by divNum). Use a try block to perform the statements. Use a catch block to catch any ArithmeticException and output an exception message with the getMessage() method. Use another catch block to catch any InputMismatchException and output an exception message with the toString() method. Note: ArithmeticException is thrown when a division by zero happens. InputMismatchException is thrown when a user enters a value of different data type than what is defined in the program. Do not include code to throw any exception in the program.

Respuesta :

The program is an illustration of exceptions

Exceptions are used to manage programs from crashing, when they encounter errors.

The program in Java, where comments are used to explain each line is as follows:

import java.util.*;

public class Main {

   public static void main(String[] args) {

       //This creates a Scanner object

       Scanner input = new Scanner(System.in);

       //This gets input for userNum

       int userNum = input.nextInt();

       //This gets input for divNum

       int divNum = input.nextInt();

       //This opens the InputMismatchException try catch

       try {

           //This opens the ArithmeticException try catch

           try{

               //This prints the division of userNum by divNum

               System.out.print(userNum/divNum);

           }

           //If divNum is 0, this catches the exception

           catch (ArithmeticException e){

               System.out.println(e.getMessage());

           }  

        }  

        //If the inputs are not integers, this catches the exception

        catch (InputMismatchException ex) {

           System.out.println(ex.getMessage());

        }

  }

}

Read more about exceptions at:

https://brainly.com/question/6864640

ACCESS MORE
EDU ACCESS
Universidad de Mexico