Program to find slant height of cone and pyramid | Java program for the above approach ; Function to calculate slant height of a cone ; Store the slant height of cone ; Print the result ; Function to find the slant height of a pyramid ; Store the slant height of pyramid ; Print the result ; Driver Code ; Dimensions of Cone ; Function Call for slant height of Cone ; Dimensions of Pyramid ; Function to calculate slant height of a pyramid
import java . io . * ; class GFG { static void coneSlantHeight ( double cone_h , double cone_r ) { double slant_height_cone = Math . sqrt ( Math . pow ( cone_h , 2 ) + Math . pow ( cone_r , 2 ) ) ; System . out . println ( " Slant ▁ height ▁ of ▁ cone ▁ is : ▁ " + slant_height_cone ) ; } static void pyramidSlantHeight ( double pyramid_h , double pyramid_s ) { double slant_height_pyramid = Math . sqrt ( Math . pow ( pyramid_s / 2 , 2 ) + Math . pow ( pyramid_h , 2 ) ) ; System . out . println ( " Slant ▁ height ▁ of ▁ pyramid ▁ is : ▁ " + slant_height_pyramid ) ; } public static void main ( String [ ] args ) { double H1 = 4.5 , R = 6 ; coneSlantHeight ( H1 , R ) ; double H2 = 4 , S = 4.8 ; pyramidSlantHeight ( H2 , S ) ; } }