Formula to calculate trapezoid Area - Android java.lang

Android examples for java.lang:Math Formula

Description

Formula to calculate trapezoid Area

Demo Code


import java.text.DecimalFormat;

public class Main{
    private static double result;
    public static double trapezoidArea(double base1, double base2,
            double height) throws InvalidInputException {
        if (base1 >= 0 && base2 >= 0 && height >= 0) {
            result = (height * (base1 + base2) / 2);
            return result;
        } else {/*  ww w  .ja v a2  s .c  om*/
            throw new InvalidInputException();
        }
    }
}

Related Tutorials