java

Write a Java Program to Calculate the Area of Circle

In this tutorial, we are going to see how to write a Java program to calculate the area of a circle. We will use the following formula to calculate the area of the circle:

area = π ⋅ radius ⋅ radius
area = π ⋅ radius2


 
We use the given formula to calculate the area of the circle.
 
 

Java Program to Calculate the Area of Circle:
import java.util.Scanner;

public class Main
{
    public static void main(String[] args) 
    {
        int radius;
        double area, pi = 3.14;
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter the radius of the circle : ");
        radius = scanner.nextInt();
        area = pi * radius * radius;
        System.out.println("The area of the circle is: "+area);
    }            
}

Output:

Enter the radius of the circle : 2
The area of the circle is: 12.56
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *