# Java Program to Find the Area of Parallelogram

This is the Java Program to Find the Area of a Parallelogram.

Problem Description

Given the dimensions of a parallelogram, find out its area.

Problem Solution

The area of a parallelogram can be calculated using the formula:

Area = base*height.

Program/Source Code

Here is the source code of the Java Program to Find the Area of a Parallelogram. The program is successfully compiled and tested using IDE IntelliJ Idea in Windows 7. The program output is also shown below.

1. ` `
2. `//Java Program to Find the Area of a Parallelogram`
3. ` `
4. `import java.io.BufferedReader;`
5. `import java.io.InputStreamReader;`
6. ` `
7. `public class AreaOfAParallelogram {`
8. `    // Function to calculate the area of a parallelogram`
9. `    public static void main(String[] args) {`
10. `        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));`
11. `        double base,height;`
12. `        System.out.println("Enter the base and the height of the parallelogram");`
13. `        try{`
14. `            base=Double.parseDouble(br.readLine());`
15. `            height=Double.parseDouble(br.readLine());`
16. `        }catch (Exception e){`
17. `            System.out.println("An error occurred");`
18. `            return;`
19. `        }`
20. `        if(base<=0 || height<=0){`
21. `            System.out.println("Wrong Input");`
22. `            return;`
23. `        }`
24. `        System.out.println("Area = " + base*height );`
25. `    }`
26. `}`
Program Explanation

1. In function main(), first, the base and height of the parallelogram are taken as input.
2. The condition if(base<=0 || height<=0) checks if the input is valid or not.
3. The print statement displays the area of the parallelogram.

Time Complexity: O(1)

Runtime Test Cases
```
Case 1 (Simple Test Case):

Enter the base and the height of the parallelogram
8.34
5.678
Area = 47.35452```

Sanfoundry Global Education & Learning Series – Java Programs.