Program to Find Area and Perimeter of Trapezium

bookmark

import java.util.*;
public class Main
{
     public static void main(String []args)
     {
        //Scanner Class instrance created
        Scanner sc=new Scanner(System.in);
        
        //Take side1,side2(both are the length of the parallel sides) and height input from the user 
        System.out.println("Enter length(parallel sides of the trapezium) : ");
        double side1=sc.nextDouble();
        System.out.println("Enter length(parallel sides of the trapezium) : ");
        double side2=sc.nextDouble();
         System.out.println("Enter length(non-parallel sides of the trapezium) : ");
        double side3=sc.nextDouble();
        System.out.println("Enter length(non-parallel sides of the trapezium) : ");
        double side4=sc.nextDouble();
        System.out.println("Enter height of the trapezium: ");
        double height = sc.nextDouble();
        
        //finding area using formula
        double area=((side1+side2)*height)/2;
        System.out.println("Area Of Trapezium : "+area); 
        //finding perimeter using formula
        double perimeter=side1+side2+side3+side4;
        System.out.print("Perimeter Of Trapezium : "+perimeter); 
     }
}

 


Output:

Enter length(parallel sides of the trapezium) : 5
Enter length(parallel sides of the trapezium) : 15
Enter length(non-parallel sides of the trapezium) : 11
Enter length(non-parallel sides of the trapezium) : 4
Enter height of the trapezium: 20
Area Of Trapezium : 200.0
Perimeter Of Trapezium : 35.0