Java Program to Calculate Area of Trapezium

Hello everyone, welcome to my new tutorial on Java Program to calculate Area of Trapezium. The trapezium is a quadrilateral with one pair of parallel opposite sides. The parallel sides of a trapezium are called bases, and the non-parallel sides of a trapezium are called legs.

In the previous tutorial, you have learned Java Program to Calculate Area and Perimeter of Parallelogram. In this tutorial, you will get the answer to your query – how do you find the area of a trapezium in Java?

The area of a trapezium can be calculated using the following formula.

Area of a Trapezium, A = h(a+b)/2

Where,

  • a and b are the bases of  the Trapezium
  • h is the altitude or height of the Trapezium.

Now let’s write the program, and explanations are given after the program.

Java Program to Calculate Area of Trapezium

What we did?

  • First of all we have imported the util package.
  • Then created a class and named it Trapezium.
  • After that started main() method of the program.
  • Then inside main() method declared variables.
  • Then created object of the Scanner class.
  • Now asked the user to enter the base1, base2, and height of the trapezium. Then read the value of base1, base2, and height of trapezium entered by the user.
  • Then calculated area of the trapezium using the formula area = ((a1+a2)*h)/2
  • Then finally displayed the value of area of the trapezium on the screen.

Now let’s check the output of the above code.

Output:

Now this tutorial on Java Program to calculate Area of Trapezium is completed. In the next tutorial, you will learn Java Program to calculate Area and Volume of Cube.


Related Tutorials…

Leave a Comment