Question
Create a java program which allows the user to enter two values (Using JOptionPane) to be divided. The application catches an exception if either of
Create a java program which allows the user to enter two values (Using JOptionPane) to be divided. The application catches an exception if either 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. The numerator and denominator variables must be assigned starting values because their values will be entered within a try block. Also declare an input String to hold the return value of the JOptionPane show input dialog() method.int numerator = 0, denominator = 0, result; String inputString;
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 Arithmetic Exception object if division by 0 is attempted. If this block executes, display an error message, and force result to 0.
Step by Step Solution
3.49 Rating (166 Votes )
There are 3 Steps involved in it
Step: 1
Program implemented as per ins...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started