Java Program to Calculate the Area and Circumference of a Circle

0

In this Tutorial we will learn to Java program to calculate the area and circumference of the circle. User will give radius as input and our program should return circumference and area.

If you don't know how to find circumference and area please refer below:

  • The area of a circle is calculated using the formula 3.14*r*r where 3.14 is Pi value and r is the radius of circle
  • The circumference of a circle is calculated using the formula 2*3.14*r.
  • The java program below uses Math.PI property of java that return approx 3.14159

Program to find circumference of circle in java


import java.util.Scanner;

public class Main
{
  public static void main(String[] args) {
      
      Scanner scanner = new Scanner(System.in);
      System.out.println("Enter the radius: ");
      
      //Read user input
      double radius = scanner.nextDouble();
      
      //To find Area = PI*(radius*radius)
      double area = Math.PI * (radius * radius);
      System.out.println("The Area of the Circle is: "+area);
      
      //close scanner
      scanner.close();
      
      //To find circumference = PI*2*radius
      double circumference = Math.PI * 2 * radius;
      System.out.println("The circumference of a circle is: "+circumference);
    
   }
}

Output:


Enter the radius: 
6
The Area of the Circle is: 113.09733552923255
The circumference of a circle is: 37.69911184307752

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.
Post a Comment (0)
Our website uses cookies to enhance your experience. Learn More
Accept !