Area of Circle

Calculate the area of a circle given its radius.

BeginnerTopic: Module 1: Basic Java Programs
Back

Java Area of Circle Program

This program helps you to learn the fundamental structure and syntax of Java programming.

Try This Code
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter radius: ");
        double r = sc.nextDouble();

        double area = Math.PI * r * r;
        System.out.println("Area of circle = " + area);

        sc.close();
    }
}
Output
Enter radius: 5
Area of circle = 78.53981633974483

Understanding Area of Circle

We use the formula area = πr² and Java's built-in Math.PI constant.

Note: To write and run Java programs, you need to set up the local environment on your computer. Refer to the complete article Setting up Java Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your Java programs.

Table of Contents