Hackerss.com is a community of amazing hackers

Hackerss is a community for developers, data scientitst, ethical hackers, hardware enthusiasts or any person that want to learn / share their knowledge of any aspect of digital technology.

Create account Log in

Posted on

Create a class for a circle in Java

Create a class for a circle - Java:

* This class is used to create a circle.
* @author Juan Antonio Brenha Moral
public class Circle {
   * This method calculate the area of a circle.
   * @param radius radius of the circle.
   * @return double Obtains the area of the circle.
   public double area(double radius) {
       //Variable to store the area
       double area = 0;
       //Calculate the area
       area = Math.PI * Math.pow(radius,2);
       //Return the area
       return area;

   * One Example
   public static void main(String args[]) throws IOException {

      Circle  circle= new Circle ();
      double area = circle.area(5);
      System.out.println("Area of a circle with radius 5 is :" + area); //78.53981633974483
Enter fullscreen mode Exit fullscreen mode

Top comments (0)