Java Program to Calculate Area and Circumference of Circle

Hello guys, in today’s post we will learn to write Java program to calculate area and circumference of circle. Writing Java program for calculating area and circumference of circle is very easy. So let’s start and see how to do it in Java.

To find area and circumference of circle first we need to know the formula. Here is the formula –

Area of circle = πrsquare units

Circumference of circle = 2πr

Where,

  • r is the radius of the circle.
  • π is a constant whose value is 3.1415 or 22/7.

Now let’s learn how to calculate them in Java.

Java Program to Calculate Area and Circumference of Circle

What we did ?

We have written Java program to calculate area and circumference of circle successfully. Now we will explain what we did to find area and circumference of a circle in Java.

  • First of all we imported util package.
  • Then we have created a public class named as Circle.
  • Inside Circle class we created main() method.
  • Then we have declared variables which are used in this program.
  • Now we created object of the Scanner class.
  • Then asked the user to enter the radius of circle.
  • In next line read the value of radius entered by the user.
  • Then calculated area of circle using formula Math.PI * r *r. Instead of using Math.PI we can also write the value of pi (3.14 or 22/7) directly.
  • In next line calculated circumference of circle using formula 2 * Math.PI * r
  • Then at last printed area and circumference of circle on screen.

Output:

So guys, this was Java program to calculate area and circumference of circle. In the next tutorial, you will learn how to write Java Program to calculate Area of Triangle. THANKS.


Related Tutorials…

Leave a Comment