logo image

Java program to calculate trapezoid circumference

Following program shows you how to calculate trapezoid circumference. This program gets trapezoid bases and sides from user and calculates circumference and prints it using following formula Circumference = base1 + base2 + side1 +side2

import java.util.Scanner;

public class MathGeometry5 {

	public static void main(String[] args) {

		double trapezoidBase1;
		double trapezoidBase2;
		double trapezoidSide1;
		double trapezoidSide2;

		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 side1 of trapezoid:");
		trapezoidSide1 = in.nextInt();

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

		double circumferenceOfTrapezoid = trapezoidBase1 + trapezoidBase2 + trapezoidSide1 + trapezoidSide2;
		System.out.println("Circumference of trapezoid is: " + circumferenceOfTrapezoid);



Please enter base1 of trapezoid:
Please enter base2 of trapezoid:
Please enter side1 of trapezoid:
Please enter side2 of trapezoid:
Circumference of trapezoid is: 25.0