If the numerator and the denominator are coprime
if ( __gcd ( i , j ) == 1 ) { String a = String . valueOf ( i ) ; String b = String . valueOf ( j ) ; System . out . print ( a + " / " + b + " , ▁ " ) ; } } } } static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; }