# Java program to calculate area of a circle

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 area of circle we are using scanner class to take input from user.

Also read – java program to calculate area of rectangle

First user enters radius as input. Then using given formula we calculate the area of a circle. Here’s the simple java program to find area of circle,

// area = pi * r * r where r is the radius of a circle

```import java.util.Scanner;

public class AreaOfCircleDemo
{
public static void main(String[] args)
{
double pi = 3.1415, area;
Scanner sc = new Scanner(System.in);
System.out.println("Area of circle : " + area);
sc.close();
}
}

```

Output:
Area of circle : 78.5

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
{
{
}

void findArea()
{
System.out.println("Area of circle = " + circle_Area);
}

void findCircumference()
{
double circle_Circumference = 2 * Math.PI * radius ;
System.out.println("Circumference of circle = " + circle_Circumference);
}

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 methods – area of circle in java using method.