Java Program to Find Area of Rhombus

In the previous article we have discussed Java Program to Find Perimeter of Parallelogram

In this article we will discuss about how to find area of rhombus.

Program to Find Area of Rhombus

Before jumping into the program directly, let’s first see how we calculate area of rhombus.

Formula for area of Parallelogram : (d1+d2)/2

Where,

  • length‘ represents length of parallelogram.
  • breadth‘ represents height of parallelogram.

Let’s see different ways to do it.

Don’t miss the chance of Java programs examples with output pdf free download as it is very essential for all beginners to experienced programmers for cracking the interviews.

Method-1: Java Program to Find Area of Rhombus By Static Value

In this method, diagonal1 and diagonal2 values are already declared in the program. Then these value will be used to calculate the area of rhombus using the formula and then the result will be displayed.

Let’s see the program to understand it more clearly.

import java.util.*;

public class Main
{
   public static void main(String args[]) 
    {   
        //Scanner class object created
        Scanner s= new Scanner(System.in);
        //diagoonal1 length declared
        double d1= 15;
        //diagoonal2 length declared
        double d2= 20;
   
        //finding area of rhombus
        double area=(d1*d2)/2;
        System.out.println("Area of Rhombus : " + area); 
    }
}
Output:

Area of Rhombus : 150.0

Method-2: Java Program to Find Area of Rhombus By User Input Value

In this method, we have taken the diagonal1 and diagonal2 input of rhombus as user input means it will ask the user to input the value for diagonal1 and diagonal2 . Then these value will be used to calculate the area of rhombus using the formula and then the result will be displayed.

Let’s see the program to understand it more clearly.

import java.util.*;

public class Main
{
   public static void main(String args[]) 
    {   
        //Scanner class object created
        Scanner s= new Scanner(System.in);
        //taking input of diagonal1 length
        System.out.println("Enter the length of diagonal1 : ");
        double d1= s.nextDouble();
        //taking input of diagonal2 length
        System.out.println("Enter the length of diagonal2 : ");
        double d2= s.nextDouble();
        //finding area of rhombus
        double area=(d1*d2)/2;
        System.out.println("Area of Rhombus : " + area);      
   }
}
Output:

Enter the length of diagonal1 : 4.5
Enter the length of diagonal2 : 5.6
Area of Rhombus : 12.6

Method-3: Java Program to Find Area of Rhombus By User Defined Method

In this method, we have implemented the same area finding logic within a user defined method say findArea() and passed the diagonal1 and diagonal2 length of rhombus as parameter to the method. This findArea() method will find the area and will display the result.

Let’s see the program to understand it more clearly.

import java.util.*;

public class Main
{
   public static void main(String args[]) 
    {   
        //Scanner class object created
        Scanner s= new Scanner(System.in);
        //taking input of diagonal1 length
        System.out.println("Enter the length of diagonal1 : ");
        double d1= s.nextDouble();
        //taking input of diagonal2 length
        System.out.println("Enter the length of diagonal2 : ");
        double d2= s.nextDouble();
        findArea(d1,d2);
    }     
        public static void findArea(double d1, double d2)
        {
        //finding area of rhombus
        double area=(d1*d2)/2;
        System.out.println("Area of Rhombus : " + area); 
        }
}
Output:

Enter the length of diagonal1 : 4.5
Enter the length of diagonal2 : 5.6
Area of Rhombus : 12.6

Provided list of Simple Java Programs is specially designed for freshers and beginners to get familiarize with the concepts of Java programming language and become pro in coding.

Related Java Programs: