887712. Area of a Circle
Easy
Area of a Circle
Summary
Find the area of a circle given its radius. This problem involves basic mathematical concepts and requires an understanding of the formula for calculating the area of a circle.
Detailed Explanation
The formula to calculate the area of a circle is A = πr^2, where A is the area and r is the radius of the circle. To solve this problem, we can use this formula and prompt the user to input the value of the radius.
Here's a step-by-step breakdown:
- Prompt the user for the radius of the circle.
- Calculate the area using the formula A = πr^2.
- Print the calculated area.
Time complexity: O(1), as we are performing constant-time operations (input, calculation, and output). Space complexity: O(1), as we are not using any additional space that scales with the input size.
Optimized Solutions
Java
import java.lang.Math;
public class AreaOfACircle {
public static void main(String[] args) {
double radius = Double.parseDouble(System.console().readLine("Enter the radius of the circle: "));
double area = Math.PI * Math.pow(radius, 2);
System.out.println("The area of the circle is " + area);
}
}