📜  求圆锥的表面积和体积的Java程序

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

求圆锥的表面积和体积的Java程序

给定圆锥的尺寸,求圆锥的表面积和体积。下面给出了计算面积和体积的公式。

锥体

锥体是一种三维几何形状。它由一个圆形的基部和一个弯曲的侧面(侧面)组成,末端是一个称为顶点或顶点的尖端。

圆锥的高度、半径和斜高

其中 r 是圆形底面的半径,h 是高度(从底面到顶点的垂直距离), s是锥体的倾斜高度。

可以使用毕达哥拉斯公式 sqrt(r * r + h * h) 计算斜高 (s)

Input : 
radius = 5
slant_height = 13
height = 12
Output :
Volume Of Cone = 314.159
Surface Area Of Cone = 282.743

Input :
radius = 6
slant_height = 10
height = 8
Output : 
Volume Of Cone = 301.593
Surface Area Of Cone = 301.593

方法 :

  • 给定圆锥的尺寸,比如圆锥的半径 R 和高度 H
  • 求 S = sqrt(R * R + H * H)
  • 应用以上公式

示例 1:

Java
// Java Program to Find the Surface Area and Volume of a
// Cone
  
import java.io.*;
  
class GFG {
    public static void main(String[] args)
    {
        // specify radius and height of cone
        double R = 6, H = 8;
  
        // calculate slant height S
        double S = Math.sqrt(R * R + H * H);
  
        // calculate surface area of cone
        double SurfaceArea
            = (Math.PI * R * R) + (Math.PI * R * S);
  
        // calculate volume of cone
        double Volume = (Math.PI * R * R * H) / 3;
  
        System.out.println("Surface area of cone is : "
                           + SurfaceArea);
  
        System.out.println("Volume of cone is : " + Volume);
    }
}


Java
// Java Program to Find the Surface Area and Volume of a
// Cone
  
import java.io.*;
  
class GFG {
    public static void main(String[] args)
    {
        // specify radius and height of cone
        double R = 3.42, H = 12;
  
        // calculate slant height S
        double S = Math.sqrt(R * R + H * H);
  
        // calculate surface area of cone
        double SurfaceArea
            = (Math.PI * R * R) + (Math.PI * R * S);
  
        // calculate volume of cone
        double Volume = (Math.PI * R * R * H) / 3;
  
        System.out.println("Surface area of cone is : "
                           + SurfaceArea);
  
        System.out.println("Volume of cone is : " + Volume);
    }
}


输出
Surface area of cone is : 301.59289474462014
Volume of cone is : 301.59289474462014

示例 2:

Java

// Java Program to Find the Surface Area and Volume of a
// Cone
  
import java.io.*;
  
class GFG {
    public static void main(String[] args)
    {
        // specify radius and height of cone
        double R = 3.42, H = 12;
  
        // calculate slant height S
        double S = Math.sqrt(R * R + H * H);
  
        // calculate surface area of cone
        double SurfaceArea
            = (Math.PI * R * R) + (Math.PI * R * S);
  
        // calculate volume of cone
        double Volume = (Math.PI * R * R * H) / 3;
  
        System.out.println("Surface area of cone is : "
                           + SurfaceArea);
  
        System.out.println("Volume of cone is : " + Volume);
    }
}
输出
Surface area of cone is : 170.81027853689216
Volume of cone is : 146.98129725379061

时间复杂度 = O(1)