Java Program to Find the Area of the Cricle

In this article, we will learn to create a program that calculates the area of the circle using a java programming language.

Area of Circle

Area = pi*r*r

where, pi = 3.14

r is the radius of the circle.

Explanation

  • First, we will create a function name area().
  • area() takes the argument as a radius and returns the calculated area of the circle
  • In the main() function, we take input of radius from the user and call the area() function.

Solution

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
import java.util.*;

class ar_cirlce {
    public static double area(int r){
        double area;

        area = 3.14*r*r;

        return area;
    }

    public static void main(String args[]){
        int radius;

        Scanner sc = new Scanner(System.in);

        radius = sc.nextInt();
        
        System.out.println(area(radius));
    }
}

Output

5
78.5


Previous Post
No Comment
Add Comment
comment url