Miscellaneous

Java Program to Calculate Area of Circle

A Java program to calculate the Area of a Circle.

Problem Description

Write a Java program to calculate the Area of a Circle.

Code

AreaOfCircle.java
public class AreaOfCircle {
    public static void main(String[] args) {
        int radius = 3;
        double area = Math.PI * radius * radius;
        System.out.println("The area of the circle is: " + area);
    }
}

Output

The area of the circle is: 28.274333882308138

Explanation

  1. Formula: PI * r * r.
  2. Math.PI: Use the built-in constant for PI.