Join
Blogs
Questions
Videos
Tags
Members
Search
 
 
Create your own blog, earn points and get popular!

Write a program to calculate rectangle area.

  1. /*
  2.  * Write a program to calculate rectangle area. Program should have class called
  3.  * Rectangle with length and width as member variables and getArea member method.
  4.  * getArea method should print area of the rectangle object.
  5.  */
  6. class Rectangle{
  7.  
  8.  int l, w;
  9.  
  10.  void setData(int x, int y){
  11.   l = x;
  12.   w = y;
  13.  }
  14.  
  15.  void getArea(){
  16.  
  17.   System.out.println("Area of Rectangle: " + (l*w));
  18.  }
  19. }
  20.  
  21. public class RectangleArea
  22. {
  23.  public static void main(String args[]){
  24.  
  25.   Rectangle r1 = new Rectangle();
  26.   r1.setData(10,15);
  27.   r1.getArea();
  28.  
  29.   Rectangle r2 = new Rectangle();
  30.   r2.setData(7,9);
  31.   r2.getArea();
  32.  }
  33. }
Your rating: None Average: 1.7 (3 votes)
Share this