-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain_84.java
More file actions
37 lines (37 loc) · 942 Bytes
/
Main_84.java
File metadata and controls
37 lines (37 loc) · 942 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
25
26
27
28
29
30
31
32
33
34
35
36
37
class NegRadiusExcep extends Exception{
public String toString(){
return "radius can't be negative";
}
public String getMessage(){
return "radius can't be negative";
}
}
public class Main_84 {
public static double area(int r) throws NegRadiusExcep{
if (r<0){
throw new NegRadiusExcep();
}
double res=Math.PI*r*r;
return res;
}
public static int divide(int a, int b) throws ArithmeticException{
int res=a/b;
return res;
}
public static void main(String[] args) {
try {
int c = divide(20, 0);
System.out.println(c);
}
catch (Exception e){
System.out.println("exception "+e);
}
try{
double ar=area(-3);
System.out.println(ar);
}
catch (Exception e){
System.out.println("exception "+e);
}
}
}