Write a program in JAVA to find area of Trapezoid class 8
Answers
Answer:
package Area;
import java.util.Scanner;
class Trapezoid
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in());
double base1, base2, height, Area, Median;
System.out.println(" Please Enter First Base of a Trapezoid = ");
base1 = sc.nextDouble();
System.out.println(" Please Enter Second Base of a Trapezoid = ");
base2 = sc.nextDouble();
System.out.println(" Please Enter the Height of a Trapezoid = ");
height = sc.nextDouble();
Area = 0.5 * (base1 + base2) * height;
System.out.format("\n The Area of a Trapezoid = %.2f\n",Area);
}
}
Explanation:
area of trapezoid is given by:- 0.5*(sum of two parallel sides)*height
so the two parallel sides of the trapezoid and the height are taken as input by user and stored in variables
base1 , base2 and height respectively.
data type of each variable is taken as double as the input and area could be in decimal values.
then area is calculated by 0.5* (base1 + base2) * height
and is ready to get printed.