Problem Description
Given the radius r of the circle, find the area of the circle.
Input format
The input contains an integer r, which represents the radius of the circle.
Output format
Output one line, including a real number, rounded to 7 digits after the decimal point, indicating the area of the circle.
Explanation: In this question, the input is an integer, but the output is a real number.
For the problem of real number output, please be sure to see clearly the requirements for real number output. For example, if you need to keep 7 decimal places in this question, your program must strictly output 7 decimal places, and output too many or too few decimal places will not work. , Will be considered an error.
If the problem of real number output is not specified, the rounding is performed by rounding.
Sample input
4
Sample output
50.2654825
Data scale and convention
1 <= r <= 10000。
Reminder: This question requires higher accuracy, please note that the value of π should be a more accurate value. You can use a constant to express π, such as PI=3.14159265358979323, or use a mathematical formula to find π, such as PI=atan(1.0)*4.
code show as below:
import java.text.DecimalFormat;
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int r=sc.nextInt();
double PI=3.14159265358979323;
double s=PI*r*r;
DecimalFormat df=new DecimalFormat("#.0000000");
System.out.println(df.format(s));
}
}
This title will be the most important is to use DecimalFormat
the method, rounded to seven decimal places; I am also the first time that this method treasure, I feel very good, it is worth learning, and encourage one another!