-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExceptionDemo2.java
More file actions
36 lines (34 loc) · 1.08 KB
/
Copy pathExceptionDemo2.java
File metadata and controls
36 lines (34 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import javax.swing.*;
public class ExceptionDemo2
{
public static void main(String[] args)
{
int numerator = 0, denominator = 0, result;
String inputString;
try
{
inputString = JOptionPane.showInputDialog(null,
"Enter a number to be divided");
numerator = Integer.parseInt(inputString);
inputString = JOptionPane.showInputDialog(null,
"Enter a number to divide into the first number");
denominator = Integer.parseInt(inputString);
result = numerator / denominator;
}
catch(ArithmeticException exception)
{
JOptionPane.showMessageDialog(null, exception.getMessage());
result = 0;
}
catch(NumberFormatException exception)
{
JOptionPane.showMessageDialog(null,
"This application accepts digits only!");
numerator = 999;
denominator = 999;
result =1;
}
JOptionPane.showMessageDialog(null, numerator + "/" +
denominator + "\nResult is " + result);
}
}