Number of smaller circles that can be inscribed in a larger circle | Java program for the above approach ; Function to count number of smaller circles that can be inscribed in the larger circle touching its boundary ; If R2 is greater than R1 ; Stores the angle made by the smaller circle ; Stores the ratio of R2 / ( R1 - R2 ) ; Stores the count of smaller circles that can be inscribed ; Stores the ratio ; If the diameter of smaller circle is greater than the radius of the larger circle ; Otherwise ; Find the angle using formula ; Divide 360 with angle and take the floor value ; Return the final result ; Driver Code
import java . util . * ; class GFG { static int countInscribed ( int R1 , int R2 ) { if ( R2 > R1 ) return 0 ; double angle ; double ratio ; int number_of_circles = 0 ; ratio = R2 / ( double ) ( R1 - R2 ) ; if ( R1 < 2 * R2 ) { number_of_circles = 1 ; } else { angle = Math . abs ( Math . asin ( ratio ) * 180 ) / 3.14159265 ; number_of_circles = ( int ) ( 360 / ( 2 * Math . floor ( angle ) ) ) ; } return number_of_circles ; } public static void main ( String args [ ] ) { int R1 = 3 ; int R2 = 1 ; System . out . println ( countInscribed ( R1 , R2 ) ) ; } }