Program to find the common ratio of three numbers | Java implementation of above approach ; Utility function ; Function to print a : b : c ; To print the given proportion in simplest form . ; Driver code ; Get the ratios ; Get ratio a : b1 ; Get ratio b2 : c ; Find the ratio a : b : c
import java . util . * ; import java . lang . * ; import java . io . * ; class GFG { static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } static void solveProportion ( int a , int b1 , int b2 , int c ) { int A = a * b2 ; int B = b1 * b2 ; int C = b1 * c ; int gcd = __gcd ( __gcd ( A , B ) , C ) ; System . out . print ( A / gcd + " : " + B / gcd + " : " + C / gcd ) ; } public static void main ( String args [ ] ) { int a , b1 , b2 , c ; a = 3 ; b1 = 4 ; b2 = 8 ; c = 9 ; solveProportion ( a , b1 , b2 , c ) ; } }