Write a java program using arrays that accepts the width and length of a rectangle and computes both its area and perimeter.
public class Rectangle {
void Area(double length, double width)
{
double area;
area = length * width;
System.out.println("Area of rectangle is : "
+ area);
}
void Perimeter(double length, double width)
{
double perimeter;
perimeter = 2 * (length + width);
System.out.println("Perimeter of rectangle is : "
+ perimeter);
}
}
class Use_Rectangle {
public static void main(String args[])
{
Rectangle rect = new Rectangle();
Scanner sc = new Scanner(System.in);
int [] params = new int[2];
for(int i = 0; i < 2; i++){
params[i] = Integer.parseInt(sc.nextLine());
}
System.out.println("Length = " + params[0]);
System.out.println("Width = " + params[1]);
rect.Area(params[0],params[1]);
rect.Perimeter(params[0], params[1]);
}
}
Comments
Leave a comment