Let’s learn java program to calculate area of a circle.

## Java program to calculate area of a circle

Java program to find area of circle and rectangle is one of the common java interview question.

In the below java program to find area of circle first we are using nextDouble() method of Scanner class to take input from user.

Also read – java program to calculate area of rectangle

Then user enters radius as input. This user entered radius is stored in double data type varible ‘radius’.

Then using area of circle formula area is calculated. Here’s the formula to find area of circle,

area = pi * r * r

where r is the radius of a circle

Here’s the simple java program to find area of circle.

import java.util.Scanner; public class CalculateAreaOfCircle { public static void main(String[] args) { double radius; double pi = 3.1415, area; Scanner sc = new Scanner(System.in); System.out.println("Please enter radius of circle: "); radius = sc.nextDouble(); area = pi * radius * radius; System.out.println("Area of circle: " + area); sc.close(); } }

**Output:**

Please enter radius of circle : 5

Area of circle : 78.53750000000001

**Java program to find area of circle using class and object**

We can also find area of circle using class and object. To calculate area and circumference of circle using given radius first create class Circle, variable/field radius methods findArea(), findCircumference() and setValues().

Here’s the java program to find area of circle using class and object.

class Circle { double radius; void setValues(double rad) { radius = rad; } void findArea() { double circleArea = Math.PI * radius * radius; System.out.println("Area of circle = " + circleArea); } void findCircumference() { double circleCircumference = 2 * Math.PI * radius ; System.out.println("Circumference of circle = " + circleCircumference); } public static void main(String[] args) { Circle obj = new Circle(); obj.setValues(5); obj.findArea(); obj.findCircumference(); } }

**Output:**

Area of circle = 78.53981633974483

Circumference of circle = 31.41592653589793

Similarly here’s the java program to find area of circle using method – area of circle in java using method.

Also read – java program to calculate area and circumference of circle using methods

**Java program to find area of circle using bufferedreader**

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class UsingBufferedReader { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Please enter radius of circle: "); double radius = Double.parseDouble(br.readLine()); double area = Math.PI * radius * radius; System.out.println("Area of circle using bufferedreader: " + area); } }

**Output:**

Please enter radius of circle: 6

Area of circle using bufferedreader: 113.09733552923255

Also read – java program to find area of circle and rectangle using interface