Area of Rhombus in java

Let’s learn area of rhombus in java.

Area of Rhombus in java

Rhombus four sides have equal length and opposite sides are equal and angles also equal. A rhombus looks like a diamond. Here’s the formula to calculate area of rhombus.

Area of rhombus = (diagonal1) * (diagonal2) / 2

To calculate area of rhombus first user enters length of the diagonals as input using nextDouble() method of Scanner class.

These user input values are stored in two double variables ‘diagonal1’ and ‘diagonal2’. Lastly area of rhombus is calculated and printed on console.

Now let’s see area of rhombus program.

import java.util.Scanner;
public class AreaOfRhombus
{
   public static void main(String[] args)
   {
      Scanner sc = new Scanner(System.in);
      System.out.println("Please enter length of diagonal 1: ");
      double diagonal1 = sc.nextDouble();
      System.out.println("Please enter length of diagonal 2: ");
      double diagonal2 = sc.nextDouble();
      double area = (diagonal1 * diagonal2) / 2;
      System.out.println("Area of Rhombus is: " + area);
      sc.close();
   }
}

Output:

Please enter length of diagonal 1:
16
Please enter length of diagonal 2:
20
Area of Rhombus is: 160.0

Please enter length of diagonal 1:
10
Please enter length of diagonal 2:
20
Area of Rhombus is: 100.0


Also read – major features of java