Circle Area with a PI Constant
Easyjava
Declare final double PI = 3.14159; and use it to compute the area of a circle from its radius.
Input: one integer — the radius.
Output: one line — the area (PI x radius x radius) rounded to two decimal places.
Example 1
Input
5
Output
78.54
- 1 <= radius <= 100000
- Use PI = 3.14159 exactly.
Hint 1
double area = PI * r * r;
Hint 2
String.format(Locale.US, "%.2f", area) rounds to two places.
Give the fixed value 3.14159 a name with final so it cannot be changed by mistake and the formula reads clearly. Format the double result to two decimals with Locale.US so the output is stable.