📜  求菱形面积的Java程序

📅  最后修改于: 2022-05-13 01:54:47.158000             🧑  作者: Mango

求菱形面积的Java程序

菱形是四个边长都相等的四边形,菱形又叫等边四边形。

求菱形面积的公式如下:

例子:

Input : p = 2, q = 3
Output: 3

Input : p = 4, q = 5
Output: 10

执行:

Java
// Java Program to Find the Area of Rhombus
public class AreaOfRhombus {
    public static void main(String[] args)
    {
        double d1, d2;
        // Diagonal 1
        d1 = 2;
        // Diagonal 2
        d2 = 3;
        if (d1 <= 0 || d2 <= 0)
            System.out.println("Length should be positive");
        else
            System.out.println("Area of rhombus = "
                               + (d1 * d2) / 2);
    }
}


输出
Area of rhombus = 3.0