Question 8 : Write a program in Java to print the area and perimeter of a rectangle. The magnitude of length and width is to be given by the user.
Java Program :
public class rectangle
{
public static void main(int l,int b)
{
int a=0,p=0;
a=l*b;
p=2*(l+b);
System.out.println("Area of the rectangle = "+a+" units");
System.out.println("Perimeter of the rectangle = "+p+" units");
}
}
Input :
l=5
b=2
Output :
Area of the rectangle = 10 units
Perimeter of the rectangle = 14 units
Java Program :
public class rectangle
{
public static void main(int l,int b)
{
int a=0,p=0;
a=l*b;
p=2*(l+b);
System.out.println("Area of the rectangle = "+a+" units");
System.out.println("Perimeter of the rectangle = "+p+" units");
}
}
Input :
l=5
b=2
Output :
Area of the rectangle = 10 units
Perimeter of the rectangle = 14 units
No comments:
Post a Comment