Java Program to Calculate the Area of Trapezium

Java program to calculate the area of Trapezium

// Java program to calculate the 
// area of Trapezium

import java.util.Scanner;

public class Main {
  static float calcuateAreaOfTrapezium(float base1, float base2, float height) {
    float result = 0.0F;

    result = 0.5F * (base1 + base2) * height;

    return result;
  }

  public static void main(String[] args) {
    Scanner SC = new Scanner(System.in);

    float base1 = 0;
    float base2 = 0;
    float height = 0;
    float area = 0;

    System.out.printf("Enter base1: ");
    base1 = SC.nextInt();

    System.out.printf("Enter base2: ");
    base2 = SC.nextInt();

    System.out.printf("Enter height: ");
    height = SC.nextInt();

    area = calcuateAreaOfTrapezium(base1, base2, height);

    System.out.printf("Area of Trapezium is: %f\n", area);
  }
}

Output

Enter base1: 2
Enter base2: 4
Enter height: 5
Area of Trapezium is: 15.000000
Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment