|
class Rectangle
{
int l, w;
int perimeter ()
{
return 2 * (l + w);
}
int area ()
{
return l * w;
}
public static void main (String [] args)
{
Rectangle rect1 = new Rectangle ();
Rectangle rect2 = new Rectangle ();
Ranch
rect1.l = 10;
rect1.w = 5;
System.out.println (rect1.perimeter ());
System.out.println (rect2.area ());
Ranch
rect2.l = 6;
rect2.w = 4;
System.out.println (rect2.perimeter ());
System.out.println (rect2.area ());
}
}
This is a piece of code to find the perimeter and area of a rectangle
The print result is indeed
30
0. This 0 is wrong. It should be 50.
20
twenty four
What is wrong with this result "0", thank you |
|