Hurry! Try our new Interactive Courses for FREE. 🥳   🚀

Java Program to Find the Area of a Parallelogram

In this tutorial, we will learn how to calculate the area of a parallelogram in java. A parallelogram is a simple quadrilateral with two pairs of parallel sides. The opposite or facing sides of a parallelogram are of equal length and the opposite angles of a parallelogram are of equal measure. The area of a parallelogram is a region covered by a parallelogram in a two-dimensional plane.

Let's see the examples below.

Input: Enter the base: 7

Enter the height: 8

Output: Area of the parallelogram: 56

Below is the pictorial representation of the same.

The above problem can be solved in the following ways:

Program 1: Find the Area of a Parallelogram

In this program, we will learn how to find the area of a parallelogram using the base and height formula.

Algorithm

  1. Start
  2. Create an instance of the Scanner class.
  3. Declare variables to store the value of the base and height of the parallelogram.
  4. Ask the user to initialize the variables.
  5. Declare another variable to store the area of the parallelogram.
  6. Use the base and height formula to calculate the area.
  7. Display the result.
  8. Stop.

Below is the code example in the Java language.

//Java Program to Calculate the Area of a Parallelogram
import java.util.Scanner;
public class Main
{
     public static void main(String []args)
     {
        //Take input from the user 
        //Create an instance of the Scanner Class
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter the base of the parallelogram: ");
        int base=sc.nextInt();
        System.out.println("Enter the height of the parallelogram: ");
        int height=sc.nextInt();
        int area=base*height;
        
        // display the area of a parallelogram
        System.out.println("Area of the parallelogram = " + area);
     }
}


Enter the base of the parallelogram: 10
Enter the height of the parallelogram: 20
Area of the parallelogram = 200

Program 2: Find the Area of a Parallelogram in Java

In this program, we will learn how to find the area of a parallelogram using trigonometry.

Algorithm

  1. Start
  2. Create an instance of the Scanner class.
  3. Declare variables to store the value of the sides of the parallelogram.
  4. Ask the user to initialize the variables.
  5. Declare another variable to store the angle between the sides of the parallelogram.
  6. Conver it into radians.
  7. Calculate the sine value of the angle.
  8. Use the trigonometric formula to calculate the area of the parallelogram,
  9. Print the value of the area of the parallelogram.
  10. Stop.

Below is the code example in the Java language.

//Java Program to Calculate the Area of a Parallelogram
import java.util.Scanner;
public class Main
{
     public static void main(String []args)
     {
        //Take input from the user 
        //Create an instance of the Scanner Class
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter the sides of the parallelogram: ");
        double a1=sc.nextDouble();
        System.out.println("Enter the sides of the parallelogram: ");
        double b1=sc.nextDouble();
        System.out.println("Enter the angle between the sides of the parallelogram: ");
        double a = sc.nextDouble();
        // converting values to radians
        double b = Math.toRadians(a);
        double area=a1*b1*(Math.sin(b));
        // display the area of parallelogram
        System.out.println("Area of the parallelogram = " + area);
     }
}
?


Enter the sides of the parallelogram: 3
Enter the sides of the parallelogram: 4
Enter the angle between the sides of the parallelogram: 90
Area of the parallelogram = 12.0

Program 3: Java Program to Find the Area of a Parallelogram in Java

In this program, we will learn how to find the area of a parallelogram using diagonals.

Algorithm

  1. Start
  2. Create an instance of the Scanner class.
  3. Declare variables to store the value of the diagonals of the parallelogram.
  4. Ask the user to initialize these variables.
  5. Declare another variable to store the angle between any two diagonals of the parallelogram.
  6. Ask the user to initialize the variable.
  7. Conver it into radians.
  8. Calculate the sine value of the angle.
  9. Use the diagonal formula to calculate the area of the parallelogram,
  10. Print the value of the area of the parallelogram.
  11. Stop.

Below is the code example in the Java language.

//Java Program to Calculate the Area of a Parallelogram
import java.util.Scanner;
public class Main
{
     public static void main(String []args)
     {
        //Take input from the user 
        //Create an instance of the Scanner Class
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter the first diagonal of the parallelogram: ");
        double d1=sc.nextDouble();
        System.out.println("Enter the second diagonal of the parallelogram: ");
        double d2=sc.nextDouble();
        System.out.println("Enter the angle between the diagonals of the parallelogram: ");
        double a = sc.nextDouble();
        // converting values to radians
        double b = Math.toRadians(a);
        double area=(d1*d2*(Math.sin(b)))/2;
        // display the area of parallelogram
        System.out.println("Area of the parallelogram = " + area);
     }
}


Enter the first diagonal of the parallelogram: 30
Enter the second diagonal of the parallelogram: 40
Enter the angle between the diagonals of the parallelogram: 30
Area of the parallelogram = 299.99999999999994