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:

  1. Prompt the user for the radius of the circle.
  2. Calculate the area using the formula A = πr^2.
  3. 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

View on GeeksforGeeks
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);
    }
}

DevExCode

Master coding interviews with Leetcode, system design, TechBit, QuickLearn, DevTips, Tech Battles, and career services.

© 2026 DevExCode. All rights reserved.