Saturday, 26 April 2014

Ex 1: Write a program in Java to implement the formula (Area = Height ×Width) to find the area of a rectangle. Where Height and Width are the rectangle‟s height and width.

class rectangle
{
int h,w;
rectangle(int x,int y)
{
h=x; w=y;
}
int area()
{
return(h*w);
}
}
class s01_01
{
public static void main(String args[])
{
rectangle r=new rectangle(10,20);
int area=r.area();
System.out.println("Area of Rectangle="+area);
}
}

No comments:

Post a Comment