ADVERTISEMENT
ADVERTISEMENT

Java program to calculate the area of Rhombus

Given diagonals, we have to calculate the area of Rhombus.
Submitted by Nidhi, on February 27, 2022

Problem Solution:

In this program, we will read diagonals from the user and calculate the area of the Rhombus. Then we will print the result.

Program/Source Code:

The source code to calculate the area of Rhombus is given below. The given program is compiled and executed successfully.

// Java program to calculate the 
// area of Rhombus

import java.util.Scanner;

public class Main {
  static float calcuateAreaOfRhombus(float diagonal1, float diagonal2) {
    float result = 0.0F;

    result = 0.5F * diagonal1 * diagonal2;
    return result;
  }

  public static void main(String[] args) {
    Scanner SC = new Scanner(System.in);

    float diagonal1 = 0;
    float diagonal2 = 0;
    float area = 0;

    System.out.printf("Enter the value of first diagonal: ");
    diagonal1 = SC.nextFloat();

    System.out.printf("Enter the value of second diagonal: ");
    diagonal2 = SC.nextFloat();

    area = calcuateAreaOfRhombus(diagonal1, diagonal2);

    System.out.printf("Area of rhombus is: %f\n", area);
  }
}

Output:

Enter the value of first diagonal: 3
Enter the value of second diagonal: 5.5
Area of rhombus is: 8.250000

Explanation:

In the above program, we imported the "java.util.Scanner" package to read input from the user. And, created a public class Main. It contain two static methods calcuateAreaOfRhombus() and main().

The calcuateAreaOfTrapezium() method is used to calculate the area of the Rhombus.

The main() method is an entry point for the program. Here, we read diagonals from the user using the Scanner class. Then we calculated the area of Rhombus using the calcuateAreaOfRhombus() method and printed the result.

Java Basic Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.