-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExcpts.java
More file actions
61 lines (53 loc) · 2.01 KB
/
Excpts.java
File metadata and controls
61 lines (53 loc) · 2.01 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// AYC-Excpts/Excpts.java
// taha burak sahin pjatk
import javax.swing.JOptionPane;
public class Excpts {
public static void main(String[] args) {
boolean noGood = true;
int number = 0;
while (noGood) {
String s = JOptionPane.showInputDialog(
null,"Enter two integers","Entering data",
JOptionPane.QUESTION_MESSAGE);
if (s == null) break;
s = s.trim();
if (s.length() == 0) continue;
int spac = s.indexOf(' ');
if (spac < 0) {
JOptionPane.showMessageDialog(
null,"<html>Wrong data!" +
"<br />Try again!!!",
"ERROR",JOptionPane.ERROR_MESSAGE);
continue;
}
try {
int n1 = Integer.parseInt(
s.substring(0,spac));
int n2 = Integer.parseInt(
s.substring(spac+1).trim());
number = n1/n2;
noGood = false;
} catch(NumberFormatException e) {
JOptionPane.showMessageDialog(
null,"<html>This were not integers!" +
"<br />Try again!!!",
"ERROR",JOptionPane.ERROR_MESSAGE);
System.err.println("EXCEPTION " +
e.getMessage() + '\n' + "STACK TRACE:");
e.printStackTrace();
} catch(ArithmeticException e) {
JOptionPane.showMessageDialog(
null,"<html>Division by zero!" +
"<br />Try again!!!",
"ERROR",JOptionPane.ERROR_MESSAGE);
System.err.println("EXCEPTION " +
e.getMessage() + '\n' + "STACK TRACE:");
e.printStackTrace();
}
}
System.out.println(
noGood ?
"Program cancelled"
: "Result of division: " + number);
}
}