Create a Java program where the user will have to enter two values(Using JOptionPane) to be divided.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter14: Exception Handling
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Create a Java program where the user will have to enter two values(Using JOptionPane) to be divided. The application catches an exception if one of the entered values is not an integer. Declare three integers—two to be input by the user and a third to hold the result after dividing the first two. 

Add a try block that prompts the user for two values, converts each entered String to an integer, and divides the values, producing result.

Add a catch block that catches an ArithmeticException object if division by 0 is attempted. If this block executes, display an error message, and force result to 0.

catch(ArithmeticException exception)

{

JOptionPane.showMessageDialog(null, exception.getMessage());

result = 0;

}

Expert Solution
steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Top down approach design
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning