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

Problem Description

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

Problem Solution

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

**Area = (diagonal1)*(diagonal2)/2.
**

Program/Source Code

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

`//Java Program to Find the Area of a Rhombus`

import java.io.BufferedReader;

import java.io.InputStreamReader;

public class AreaOfARhombus {

`// Function to calculate the area of a rhombus`

public static void main(String[] args) {

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

double l1,l2;

System.out.println("Enter the length of the diagonals of the rhombus");

try{

l1=Double.parseDouble(br.readLine());

l2=Double.parseDouble(br.readLine());

}catch (Exception e){

System.out.println("An error occurred");

return;

`}`

if(l1<=0 || l2<=0){

System.out.println("Wrong input");

return;

`}`

System.out.println("Area = " + (l1*l2)/2 );

`}`

`}`

Program Explanation

1. In function main(), first, the length of the diagonals of the rhombus is taken as input.

2. The condition if(l1<=0 || l2<=0) checks if the input is valid or not.

3. The print statement displays the area of the rhombus.

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

advertisement

advertisement

**Time Complexity: O(1)**

Runtime Test Cases

Case 1 (Simple Test Case): Enter the length of the diagonals of the rhombus 23 45 Area = 517.5

**Sanfoundry Global Education & Learning Series – Java Programs.**

Check this: Programming Books | Programming MCQs

**Next Steps:**

- Get Free Certificate of Merit in Java Programming
- Participate in Java Programming Certification Contest
- Become a Top Ranker in Java Programming
- Take Java Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

**Related Posts:**

- Buy Programming Books
- Practice Programming MCQs
- Practice Information Technology MCQs
- Buy Java Books
- Apply for Java Internship