Longest rod that can be inserted within a right circular cylinder | Java Program to find the longest rod that can be fit within a right circular cylinder ; Function to find the side of the cube ; height and radius cannot be negative ; length of rod ; Driver code
import java . io . * ; class GFG { static float rod ( float h , float r ) { if ( h < 0 && r < 0 ) return - 1 ; float l = ( float ) ( Math . sqrt ( Math . pow ( h , 2 ) + 4 * Math . pow ( r , 2 ) ) ) ; return l ; } public static void main ( String [ ] args ) { float h = 4 ; float r = 1.5f ; System . out . print ( rod ( h , r ) ) ; } }