Java Program to find Area of a Parallelogram

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

package Area;

import java.util.Scanner;

public class AreaOfParallelogram1 {
	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 Parallelogram Base =  ");
		pgbase = sc.nextDouble();
		
		System.out.print("Please Enter the Parallelogram Height = ");
		pgheight = sc.nextDouble();

		pgArea = pgbase * pgheight;

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

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

package 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