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 rectangle in Java

Create a class for a rectangle - Java:

 * This class creates a rectangle.
 * @author 
 * @version 1.0
public class Rectangle {
   * This method calculates the area of a rectangle.
   * @param length the length of the rectangle.
   * @param width the width of the rectangle.
   * @return double Obtains the area of the rectangle.
   public double area(double length, double width) {
       //Variable to store the area
       double area = 0;
       //Calculate the area
       area = length * width;
       //Return the area
       return area;

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

      Rectangle  rectangle= new Rectangle ();
      double area = rectangle.area(10, 20);
      System.out.println("Area of 10 and 20 is :" + area); //200
Enter fullscreen mode Exit fullscreen mode

Top comments (0)