Java Program to find Area of a Parallelogram

Write a Java program to find the area of a parallelogram with an example. This example allows us to enter the parallelogram base and height, and the product of both gives the area. Thus, the Area equals the base multiplied by the height.

import java.util.Scanner;

public class Example {
	private static Scanner sc;

	public static void main(String[] args) {
		double pgbase, pgheight, pgArea; 
		sc = new Scanner(System.in);
		
		System.out.print("Please Enter the Base =  ");
		pgbase = sc.nextDouble();
		
		System.out.print("Please Enter the Height = ");
		pgheight = sc.nextDouble();

		pgAr = pgbase * pgheight;

		System.out.format("The Area = %.2f",pgAr);
	}
}
Please Enter the Base =  27
Please Enter the Height = 19
The Area = 513.00

In this Java program, we declared a ParallelogramArea function that returns the Parallelogram area.

import java.util.Scanner;

public class AreaOfParallelogram2 {
	private static Scanner sc;

	public static void main(String[] args) {
		float pgbase, pgheight, pgArea; 
		sc = new Scanner(System.in);
		
		System.out.print("Please Enter the Parallelogram Base =  ");
		pgbase = sc.nextFloat();
		
		System.out.print("Please Enter the Parallelogram Height = ");
		pgheight = sc.nextFloat();

		pgArea = ParallelogramArea(pgbase, pgheight);

		System.out.format(" The Area of a Parallelogram = %.2f",pgArea);
	}
	
	public static float ParallelogramArea(float pgbase, float pgheight) {
		return pgbase * pgheight;
	}
}
Java Program to find Area of a Parallelogram 1