Untitled
unknown
plain_text
2 years ago
1.1 kB
11
Indexable
import java.util.Scanner;
class Circle {
private double radius;
// Parameterized constructor to set the radius
public Circle(double radius) {
this.radius = radius;
}
// Method to calculate the circumference of the circle
public double calculateCircumference() {
return 2 * Math.PI * radius;
}
// Method to calculate the area of the circle
public double calculateArea() {
return Math.PI * radius * radius;
}
}
public class CircleDemo {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Get the radius from the user
System.out.print("Enter the radius of the circle: ");
double radius = scanner.nextDouble();
// Create a Circle object with the provided radius
Circle circle = new Circle(radius);
// Calculate and display the circumference and area
System.out.println("Circumference of the circle: " + circle.calculateCircumference());
System.out.println("Area of the circle: " + circle.calculateArea());
scanner.close();
}
}
Editor is loading...
Leave a Comment