-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExceptions.java
More file actions
24 lines (21 loc) · 776 Bytes
/
Copy pathExceptions.java
File metadata and controls
24 lines (21 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public class Exceptions {
static int div(int x, int y) throws ArithmeticException {
if(y == 0){
throw new ArithmeticException("Divided by zero");
}
//If you don't want fractions smaller than 1
else if(y > x) {
throw new ArithmeticException("Nominator is smaller than denominator");
}
//If the two numbers cannot be the same for your program
else if(y == x) {
throw new ArithmeticException("Nominator and denominator are the same");
}
else {
return x/y;
}
}
public static void main(String[] args){
System.out.println(div(4, 4));
}
}