WAP to read base/length , width and height of a IIgm & calculate its area and perimeter.
Answers
Answered by
1
Answer:
x=int(input("enter length:"))
y=int(input("enter width:"))
z=int(input("enter height:"))
area=x*z
perimeter=2(x*y)
print("area of parallelogram:",area)
print("perimeter of parallelogram:",perimeter)
Answered by
16
★
import java.util.Scanner;
public class Main {
public static void main(String [] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the length of base: ");
int base = sc.nextInt();
System.out.print("Enter the width: ");
int width = sc.nextInt();
System.out.print("Enter the height: ");
int height = sc.nextInt();
System.out.println("The perimeter is " + 2 * (base + width));
System.out.println("The area is " + base * height);
}
}
★
- The Scanner class is used to read input from the user.
- The program prompts the user to enter the length of the base, width, and height of the parallelogram, and reads the input values using nextInt() method of the Scanner class.
- The program calculates the perimeter of the parallelogram using the formula 2 * (base + width) and displays the result using println() method.
- The program calculates the area of the parallelogram using the formula base * height and displays the result using println() method.
Similar questions