Answer to Question #314095 in Java | JSP | JSF for Jay

Question #314095

Write a java program using arrays that accepts the width and length of a rectangle and computes both its area and perimeter.




1
Expert's answer
2022-03-19T02:24:41-0400
 
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]);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS