-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC37_throwAndThrows.java
More file actions
39 lines (35 loc) · 1010 Bytes
/
C37_throwAndThrows.java
File metadata and controls
39 lines (35 loc) · 1010 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
38
39
import java.util.Scanner;
class negativeRadiusException extends Exception{
public String getMessage(){
return "Radius can't be negative";
}
}
public class C37_throwAndThrows {
public static double area(int r)throws negativeRadiusException{
if(r<0){
throw new negativeRadiusException();
}
double result = Math.PI * r * r;
return result;
}
public static int divide(int a, int b) throws ArithmeticException{
int result = a/b;
return result;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
try{
int c = divide(6, 1);
System.out.println(c);
int r = sc.nextInt();
System.out.println(area(r));
}
catch(negativeRadiusException e){
System.out.println(e.getMessage());
}
catch(Exception e){
System.out.println("Exception " + e);
}
sc.close();
}
}