Java Program to find Area of a Rhombus

Write a Java Program to find the Area of a Rhombus with an example. This Java example allows to enter Rhombus diagonals and calculates the area using a mathematical formula (d1 * d2)/2. 

package Area;

import java.util.Scanner;

public class AreaOfRhombus1 {
	private static Scanner sc;

	public static void main(String[] args) {
		double rhomDg1, rhomDg2, rhomArea;
		sc = new Scanner(System.in);
		
		System.out.println("Enter Rhombus First & Second Diagonal = ");
		rhomDg1 = sc.nextDouble();
		rhomDg2 = sc.nextDouble();

		rhomArea = (rhomDg1 * rhomDg2)/2; 

		System.out.format("The Area of a Rhombus = %.2f", rhomArea);
	}
}
Enter Rhombus First & Second Diagonal = 
22
28
The Area of a Rhombus = 308.00

In this Java program, we declared a calRhombusArea function that returns the rhombus area.

package Area;

import java.util.Scanner;

public class AreaOfRhombus2 {
	private static Scanner sc;

	public static void main(String[] args) {
		float rhomDg1, rhomDg2, rhomArea;
		sc = new Scanner(System.in);	
		
		System.out.println("Enter Rhombus First & Second Diagonal = ");
		rhomDg1 = sc.nextFloat();
		rhomDg2 = sc.nextFloat();

		rhomArea = calRhombusArea(rhomDg1, rhomDg2);
		
		System.out.format("The Area of a Rhombus = %.2f", rhomArea);
	}
	public static float calRhombusArea(float rhomDg1, float rhomDg2)
	{
		return (rhomDg1 * rhomDg2)/2; 
	}
}
Java Program to find Area of a Rhombus 1