# Area of circle program in Java

In this post, you will know different Java programs to find the area of the circle. As we all know, the area of the circle is the measure of the space or region enclosed inside the circle. In geometry, the area enclosed by a circle of radius **r** is **πr2**. Here is the simple formula for calculating the area of the circle -

**Area = pi * r**^{2}

## Java program to calculate the area of circle using static method

In this post, you will learn how to calculate the area of the circle using a static method. Here, we have declared an integer type variable '**r**' which holds the radius of the circle and one double type variable area which holds the formula to calculate the area of the circle.

```
public class AreaOfCircle
{
public static void main(String args[])
{
int r = 24;
double area = (22*r*r)/7 ;
System.out.println("Area of Circle : " + area);
}
}
```

**Output of the above code:**

`Area of Circle : 1810.0`

## Java program to calculate the area of circle using diameter

Diameter is the distance across the circle passing through the centre. We can also calculate the area of the circle if we know the diameter. Either, we can divide the diameter by 2 and calculate the area using the above process, like this -

```
public class AreaOfCircle
{
public static void main(String args[])
{
int diameter = 24;
int radius = diameter/2;
double PI = 3.142;
double area = PI * (radius*radius);
System.out.println("Area of Circle : " + area);
}
}
```

**Output of the above code:**

`Area of Circle : 452.448`

## Java program to calculate the area of circle using math library

The given program calculates the area and circumference of the circle using a math library.

```
public class AreaOfCircle
{
public static void main(String args[])
{
int radius = 5;
double area = Math.PI * (radius * radius);
System.out.println("The area of circle : " + area);
double circumference= Math.PI * 2*radius;
System.out.println( "The circumference of the circle : "+circumference) ;
}
}
```

**Output of the above code:**

```
The area of circle : 78.53981633974483
The circumference of the circle : 31.41592653589793
```

## Java program to calculate the area of circle using Inheritance

The given program calculates the area of circle using the inheritance.

```
import java.util.Scanner;
class CalculateArea
{
double area;
void circle(double r)
{
area= (22*r*r)/7;
}
}
public class AreaOfCircle extends CalculateArea
{
public static void main(String args[])
{
Scanner s= new Scanner(System.in);
System.out.println("Enter the radius:");
double radius= s.nextDouble();
AreaOfCircle a=new AreaOfCircle();
a.circle(radius);
System.out.println("Area of Circle: " + a.area);
}
}
```

**Output of the above code:**

```
Enter the radius:30
Area of Circle: 2828.5714285714284
```

### Related Articles

**GCD of two numbers in Java**

Floyd triangle in Java

Electricity bill program in Java

Java program to count the occurrences of each character

nth prime number in Java

Java random number between 1 and 10

Java program to find the greatest of three numbers

Capitalize first letter of each word Java

Convert binary to decimal in Java

Convert decimal to binary in Java

Convert decimal to octal in Java

Convert decimal to hexadecimal in Java

Simple interest program in Java

Check whether the given number is even or odd in java

Print prime numbers from 1 to 100 in Java

Java prime number program

Java program to convert celsius to fahrenheit

Fibonacci series program in Java

Java program to check leap year

Java program to find factorial of a number

Floyd triangle in Java

Electricity bill program in Java

Java program to count the occurrences of each character

nth prime number in Java

Java random number between 1 and 10

Java program to find the greatest of three numbers

Capitalize first letter of each word Java

Convert binary to decimal in Java

Convert decimal to binary in Java

Convert decimal to octal in Java

Convert decimal to hexadecimal in Java

Simple interest program in Java

Check whether the given number is even or odd in java

Print prime numbers from 1 to 100 in Java

Java prime number program

Java program to convert celsius to fahrenheit

Fibonacci series program in Java

Java program to check leap year

Java program to find factorial of a number