-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAreaofCircle.java
More file actions
24 lines (18 loc) · 873 Bytes
/
AreaofCircle.java
File metadata and controls
24 lines (18 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Importing the Scanner class to take user input
import java.util.Scanner;
class AreaofCircle {
public static void main(String[] args) {
// Creating a Scanner object to read input from the user
Scanner sc = new Scanner(System.in);
// Declaring variables for radius and area of the circle
double radius;
double areaofCircle;
// Prompting the user to enter the radius of the circle
System.out.println("Enter the radius of the circle:");
radius = sc.nextDouble(); // Reading radius input from user
// Calculating the area of the circle using the formula: π * r^2
areaofCircle = Math.PI * radius * radius;
// Displaying the calculated area
System.out.println("Area of the circle with radius " + radius + " is " + areaofCircle);
}
}