text: Find Recurring Sequence in a Fraction | Java program to find repeating sequence in a fraction ; This function returns repeating sequence of a fraction . If repeating sequence doesn 't  exits, then returns empty String ; Initialize result ; Create a map to store already seen remainders . Remainder is used as key and its position in result is stored as value . Note that we need position for cases like 1 / 6. In this case , the recurring sequence doesn 't  start from first remainder. ; Find first remainder ; Keep finding remainder until either remainder becomes 0 or repeats ; Store this remainder ; Multiply remainder with 10 ; Append rem / denr to result ; Update remainder ; Driver code
code: import java . util . * ; class GFG { static String fractionToDecimal ( int numr , int denr ) { String res = " " ; HashMap < Integer , Integer > mp = new HashMap < > ( ) ; mp . clear ( ) ; int rem = numr % denr ; while ( ( rem != 0 ) && ( ! mp . containsKey ( rem ) ) ) { mp . put ( rem , res . length ( ) ) ; rem = rem * 10 ; int res_part = rem / denr ; res += String . valueOf ( res_part ) ; rem = rem % denr ; } if ( rem == 0 ) return " " ; else if ( mp . containsKey ( rem ) ) return res . substring ( mp . get ( rem ) ) ; return " " ; } public static void main ( String [ ] args ) { int numr = 50 , denr = 22 ; String res = fractionToDecimal ( numr , denr ) ; if ( res == " " ) System . out . print ( " No ▁ recurring ▁ sequence " ) ; else System . out . print ( " Recurring ▁ sequence ▁ is ▁ " + res ) ; } }