Largest sphere that can be inscribed within a cube which is in turn inscribed within a right circular cone | Java Program to find the biggest sphere which is inscribed within a cube which in turn inscribed within a right circular cone ; Function to find the radius of the sphere ; height and radius cannot be negative ; radius of the sphere ; Driver code
import java . lang . Math ; class GFG { static float sphereSide ( float h , float r ) { if ( h < 0 && r < 0 ) return - 1 ; float R = ( float ) ( ( h * r * Math . sqrt ( 2 ) ) / ( h + Math . sqrt ( 2 ) * r ) ) / 2 ; return R ; } public static void main ( String [ ] args ) { float h = 5 , r = 6 ; System . out . println ( sphereSide ( h , r ) ) ; } }