Skip to content
Related Articles

Related Articles

Java Program to Find the Area of Trapezium

Improve Article
Save Article
  • Difficulty Level : Expert
  • Last Updated : 03 Aug, 2022
Improve Article
Save Article

A trapezium is a convex quadrilateral, which has only two parallel sides and the other two sides are non-parallel. The non-parallel sides of the trapezium are referred to as its legs while the parallel sides are called the bases. It is also called a trapezoid. A parallelogram is also often referred to as a trapezoid with two parallel sides.

In the figure below, AB and DC are parallel to each other while AD and BC are the non-parallel sides. ‘h’ is also the distance that indicates the height of the trapezium between the two parallel sides.

Area of trapezium:

Area = 1/2*(sum of parallel sides)*height of the trapezium

Example:

Input : base1 = 3, base2 = 4, height = 6
Output: area = 21
Input : base1 = 5, base2 = 7, height = 3 
Output: area = 18

Approach:

  1. Take three input as two bases of the trapezium and height.
  2. Apply the area of the trapezium formula to calculate the area.
  3. Print the area.

Below is the implementation of the above approach:

Java




// Java Program to Find the Area of Trapezium
 
import java.io.*;
 
class GFG {
    public static void main(String[] args)
    {
        double base_1 = 10.00;
 
        double base_2 = 20.00;
 
        double height = 50.00;
 
        // formula for calculating the area
        double area_of_trapezium
            = ((base_1 + base_2) * height) / 2;
 
        // printing the area
        System.out.println("Area of trapezium:"
                           + area_of_trapezium);
    }
}


Output

Area of trapezium:750.0

Time complexity: O(1)  // since performing constant operations

Space complexity: O(1)

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!