-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircle.java
More file actions
35 lines (28 loc) · 998 Bytes
/
Circle.java
File metadata and controls
35 lines (28 loc) · 998 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
public class Circle {
private static final double PI = Math.PI; // Use Math.PI for higher precision
public static double calculateArea(double radius) {
if (radius < 0) {
throw new IllegalArgumentException("Radius cannot be negative.");
}
return PI * radius * radius;
}
public static void main(String[] args) {
double radius = 5;
double area = calculateArea(radius);
System.out.println("The area is: " + area);
}
}
public class Circle {
private static final double PI = Math.PI; // Use Math.PI for higher precision
public static double calculateArea(double radius) {
if (radius < 0) {
throw new IllegalArgumentException("Radius cannot be negative.");
}
return PI * radius * radius;
}
public static void main(String[] args) {
double radius = 5;
double area = calculateArea(radius);
System.out.println("The area is: " + area);
}
}