Java Program to Find Area of a Circle
The formula for finding area of a circle is,
area = PI * radius * radius
Where PI is a constant (approximately 3.1416) and radius is the radius of the circle.
Calculate Area of a Circle in Java
The following Java program calculates the area of a circle given the radius of the circle. This program demonstrates a number of key concepts in Java programming,
- How to obtain user input from console
- How to write output to console
- How to use IO classes and decorator pattern
- Using library classes such as Math, BufferedReader, Double etc.
- Performing mathematical calculations
// Java program to calculate area of a circle import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class CircleArea { public static void main(String[] args) throws IOException{ BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Please enter the radius of the circle : "); double radius = Double.parseDouble(reader.readLine()); double area = Math.PI * radius * radius; System.out.println("Area of the circle with radius "+radius+" is : "+area); } }