Task: Java Program to Calculate Area of Circle

## What is the formula for calculating Area of Circle?

The required formula for calculating area of circle is:

area = π . r^{2}

Where r is the radius of the circle and π is a mathematical constant with fixed value 3.1415.

We should declare a constant for pi in this Java program, it will enhance program readability and clarity. Here is a detailed explaination on How to Declare a Constant in Java Programs With Examples.

### The source code of the Java program to input radius and find area of circle

/* Write a Java Program to input radius of a circle and display the area of circle. Use the formula: area = π . r2 where r is radius and π is a mathematical constant with constant value 3.1415 Use a named constant for π. */ package areaofcircle; /** * @author EasyCodeBook.com */ import java.util.Scanner; public class AreaOfCircle { public static void main(String[] args) { double radius, area; final double PI = 3.1415; Scanner input = new Scanner(System.in); System.out.print("Enter radius of circle="); radius = input.nextDouble(); area = PI * radius *radius; System.out.print("Area of Circle=" + area); } }

#### The output of Java Program to calculate area of circle

run:

Enter radius of circle=5

Area of Circle=78.53750000000001BUILD SUCCESSFUL (total time: 21 seconds)

1,149 total views, 4 views today

Hey there! This is my first comment here so I just wanted to give a quick shout out and say I reallyenjoy reading your blog posts.

I found simply the info I already searched everywhere and just couldn’t come across. What an ideal web site.

Excellent post. I will be going through some of these issues as well.

I think the admin of this web site is truly workinghard in support of his website, since here every data is quality based data.

Hi there, You have performed an incredible job.I’ll definitely diggg it and for my part recommend to my friends.I am sure they will be

Hello there, just became aware of your blog through Google, and found that it is truly informative.I am going to watch out for brussels.

I’ve got some suggestions for your blog you might be interestedin hearing. Either way, great site and I look forward to seeing it improve over time.