Thursday, February 2, 2023

Find the area and perimeter of a circle

Write a Java program to print the area and perimeter of a circle.

In geometry, the area enclosed by a circle of radius r is πr2. Here the Greek letter π represents a constant, approximately equal to 3.14159, which is equal to the ratio of the circumference of any circle to its diameter.

The circumference of a circle is the linear distance around its edge.

Pictorial Representation:

Given Solution:

Java Code:

public class Exercise11 {

   private static final double radius = 7.5;

    public static void main(String[] args) {

        double perimeter = 2 * Math.PI * radius;

        double area = Math.PI * radius * radius;

        System.out.println("Perimeter is = " + perimeter);

        System.out.println("Area is = " + area);

    }

}

Output:

Perimeter is = 47.12388980384689                                                                             

Area is = 176.71458676442586

No comments:

Post a Comment

Popular Posts