forked from TimSongCoder/LearnJavaForAndroid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircleInfo.java
More file actions
31 lines (29 loc) · 933 Bytes
/
Copy pathCircleInfo.java
File metadata and controls
31 lines (29 loc) · 933 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
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.MathContext;
public class CircleInfo{
public static void main(String[] args){
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try{
do{
System.out.println("Enter the radius of the circle:");
String text = br.readLine();
double radius = Double.parseDouble(text);
System.out.println("Circumference: " + getRoundedResult(2*Math.PI*radius));
System.out.println("Area: " + getRoundedResult(Math.PI*radius*radius));
System.out.println();
}while(true);
}catch(NumberFormatException nfe){
nfe.printStackTrace();
}catch(IOException ioe){
ioe.printStackTrace();
}
}
static double getRoundedResult(double original){
BigDecimal bd = new BigDecimal(original);
bd = bd.round(new MathContext(3));
return bd.doubleValue();
}
}