Computer Science, asked by MISTERPRO, 4 days ago

Q6> Design a program that prompts the user to type in the length and width of a rectangular field and computes it's area and perimeter. [ Area = Length x Width and Perimeter = 2(Length + Width) ]​

Answers

Answered by Anonymous
0

Answer:

import java.util.Scanner;

class Rectangle

{

public static void main(String[] args)

{

//Declaration

Scanner input = new Scanner(System.in);

double l, b;

double area, perimeter;

//Initialization

area = 0.0;

perimeter - 0.0;

//Prompt and accept the length and the breadth of the rectangle from user

System.out.println("Enter the length and breadth of the rectangle: ");

l = input.nextDouble();

b = input.nextDouble();

//Compute area and perimeter of the rectangle

area = l * b;

perimeter = 2 * (l + b);

//Display

System.out.println("The area of the rectangle is = " + area);

System.out.println("The perimeter of the rectangle is = " + perimeter);

}

}

Answered by arajrav2103
0

Answer:

def area(length, width):

   ans = float(length * width)

   print("Area is: ", round(ans, 2))

def perimeter(length, width):

   ans = float(2*(length + width))

   print("Perimeter is: ", round(ans, 2))

length1 = float(input("Enter the value of length: "))

width1 = float(input("Enter the value of width: "))

if length1 <= 0 or width1 <= 0:

   print("Invalid input!")

else:

   area(length1, width1)

   perimeter(length1, width1)

Explanation:

Hope this will help you

Similar questions