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
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)