-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathCircleComputation.java
More file actions
43 lines (35 loc) · 1.02 KB
/
CircleComputation.java
File metadata and controls
43 lines (35 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
34
35
36
37
38
39
40
41
42
43
/**
* Write a program, which prompts user for a radius (of double)
* and compute the area and perimeter of a circle.
*
* The output shall look like:
*
* Enter the radius: 1.2
* The area is 4.5239
* The perimeter is 7.5398223686155035
*
* Hints: π is kept in a constant called Math.PI.
*/
package javaexercises.keyboard;
import java.util.Scanner;
/**
*
* @author User
*/
public class CircleComputation {
public static void main(String[] args) {
CircleComputation aCircleComputation = new CircleComputation();
aCircleComputation.runComputation();
}
private void runComputation()
{
Scanner in = new Scanner(System.in);
double radius;
System.out.printf("Enter the radius: ");
radius = in.nextDouble();
double area = Math.PI * Math.pow(radius, 2);
System.out.printf("\nThe area is %1$.4f", area);
double perimeter = 2*Math.PI * radius;
System.out.printf("\nThe perimeter is %1$.16f\n", perimeter);
}
}