logo image

Java program to calculate trapezoid area

Following program shows you how to calculate trapezoid area. This program gets trapezoid base and height from user and calculates area and prints it using following formula Area = (base1 + base2) X height /2

import java.util.Scanner;

public class MathGeometry4 {

	public static void main(String[] args) {

		double trapezoidBase1;
		double trapezoidBase2;
		double trapezoidHeight;

		Scanner in = new Scanner(System.in);

		System.out.println("Please enter base1 of trapezoid:");
		trapezoidBase1 = in.nextInt();

		System.out.println("Please enter base2 of trapezoid:");
		trapezoidBase2 = in.nextInt();

		System.out.println("Please enter height of trapezoid:");
		trapezoidHeight = in.nextInt();

		double areaOfTrapezoid = (trapezoidBase1 + trapezoidBase2) * trapezoidHeight / 2;
		System.out.println("Area of trapezoid is: " + areaOfTrapezoid);



Please enter base1 of trapezoid:
Please enter base2 of trapezoid:
Please enter height of trapezoid:
Area of trapezoid is: 19.5