-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculateCirclePerimeterExample.java
More file actions
33 lines (24 loc) · 1.02 KB
/
CalculateCirclePerimeterExample.java
File metadata and controls
33 lines (24 loc) · 1.02 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
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class CalculateCirclePerimeterExample{
public static void main(String[] args) {
int radius=0;
System.out.println("Please enter radius of a circle");
try{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
radius = Integer.parseInt(br.readLine());
}catch(NumberFormatException ne){
System.out.println("Sorry, invalid number "+ne);
System.exit(0);
}catch(IOException ioe){
System.out.println("IO Error"+ioe);
System.exit(0);
}
// we use Math.PI to get the value of 3.14
//circle area = PI*radius*radius
double perimeter = 2 * Math.PI * radius;
System.out.println("Perimeter of a circle is " + perimeter);
}
}