Java Program to Calculate Area of Circle

By | July 1, 2019

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 = π . r2

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

Java program to input radius and find area of circle

Java program to input radius and find area of circle

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)

7 thoughts on “Java Program to Calculate Area of Circle

  1. cshooling

    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.

    Reply
  2. ergionalization

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

    Reply
  3. ismpleton

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

    Reply
  4. aprallelogram

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

    Reply
  5. csenario

    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

    Reply
  6. rpocedural

    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.

    Reply
  7. htriller

    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.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *