21 total views

The program to compute the area of a circle in Java language is a simple demonstration of evaluating an expression. This formula for an area of a circle is the expression that we need to evaluate to get the expected results.

It is intended for beginners of Java programming language.

It is compiled using JDK 8u111 with Netbean IDE 8.2 on a Windows 7 64-bit PC. You can also compile and run the program using Command line utility in Windows.

Contents

## Problem Definition

A circle is a basic geometric shape with a radius and a diameter. The diameter length is twice the length of radius.

`diameter = `

The area of circle is given below.

`Area of a Circle = `

## Flowchart – Area of Circle

The public class of this program is **AreaCircle()** with a constructor that set radius for the circle. Then the method **area()** computes the area of the circle and prints the output. The method **area()** is called using an object of class **AreaCircle()**. The output of the program is given in the next section.

## Program Code

```
class AreaCircle
{
int radius;
int x;
AreaCircle(int x)
{
radius = x;
}
void area()
{
double area,pi;
pi=3.14;
area = pi * radius * radius;
System.out.println("Area of Circle=" + area);
}
public static void main(String args[])
{
AreaCircle Cir1 = new AreaCircle(10);
Cir1.area();
}
}
```

## Output – Area of Circle

The output of the program for an input (** radius = 10** ) is given below.

`Area of Circle = 314.0`

**Related Articles:-**

- Program to add two numbers in Java.
- Program to compute area of a triangle in Java.
- Program to compute average of an array of integers.
- Program to compute average marks of students.