Java program to calculate area of a circle

Let’s learn java program to calculate area of a circle.

Java program to calculate area of a circle

Java program to find area of circle and rectangle is one of the common java interview question.

java program to calculate area of a circle

In the below java program to find area of circle first user enters radius as input using nextDouble() method of Scanner class.

This input is stored in double data type variable ‘radius’.

Then using area of circle formula area is calculated. Here’s the formula to find area of circle,

area = pi * r * r

where r is the radius of a circle

Here’s the simple java program to find area of circle.

import java.util.Scanner;
public class CalculateAreaOfCircle
{
   public static void main(String[] args)
   {
      double radius;
      double pi = 3.1415, area;
      Scanner sc = new Scanner(System.in);
      System.out.println("Please enter radius of circle: ");
      radius = sc.nextDouble();
      area = pi * radius * radius;
      System.out.println("Area of circle: " + area);
      sc.close();
   }
}


Output:
Please enter radius of circle : 5
Area of circle : 78.53750000000001


Similarly here’s the java program to find area of circle using method.


Do not stop learning learn java programming and learn how to code.