Area of a circle
The area of a circle is the number of square units within the circle. To calculate the area of a circle the standard formula is: Area = Pi R Square
Area of circle = (A = πr²)
Logic
Here we have taken radius as input from the user, and to calculate the area of the circle we have to multiply the value of pi with the square of the radius.
Value of Pi = (3.14159)
Program
import java.util.Scanner; public class AreaOfCircle { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter radius of the circle : "); float radius = scanner.nextFloat(); // Calculate area of circle double area = 3.14 * (radius * radius); System.out.println("Area of circle : " + area); } }
Output
Enter radius of the circle : 25.125
Area of circle : 1982.1740625
Know more about Pi? – What is Pi?