Write a Java Program to find the Area of a Rhombus with an example. This example allows one to enter the Rhombus diagonals and calculates the area using a mathematical formula (d1 * d2)/2.
import java.util.Scanner; public class Example { private static Scanner sc; public static void main(String[] args) { double rhomDg1, rhomDg2, rhomAr; sc = new Scanner(System.in); System.out.println("Enter First & Second Diagonal = "); rhomDg1 = sc.nextDouble(); rhomDg2 = sc.nextDouble(); rhomAr = (rhomDg1 * rhomDg2)/2; System.out.format("The Area = %.2f", rhomAr); } }
Enter First & Second Diagonal =
22
28
The Area = 308.00
In this program, we declared a calRhombusArea function that returns the rhombus 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 Perimeter of a Rhombus
Write a Java Program to Find the Perimeter of a Rhombus with an example. This example allows to enter the rhombus side, and the area is four times the side.
import java.util.Scanner; public class PerimeterOfRhombus1 { private static Scanner sc; public static void main(String[] args) { double rhomside, rhomPerim; sc = new Scanner(System.in); System.out.print("Please Enter Rhombus Side = "); rhomside = sc.nextDouble(); rhomPerim = 4 * rhomside; System.out.format("The Perimeter of a Rhombus = %.2f\n", rhomPerim); } }
In this Program, we created a function that returns the Rhombus perimeter.
import java.util.Scanner; public class PerimeterOfRhombus2 { private static Scanner sc; public static void main(String[] args) { float rhomside, rhomPerim; sc = new Scanner(System.in); System.out.print("Please Enter Side = "); rhomside = sc.nextFloat(); rhomPerim = rhombusPerimeter(rhomside); System.out.format("The Perimeter = %.2f", rhomPerim); } public static float rhombusPerimeter(float rhomside) { return 4 * rhomside; } }
Please Enter Side = 13
The Perimeter = 52.00