First occurrence of a digit in a given fraction | Java program to find first occurrence of c in a / b ; Function to print the first digit ; Reduce the number to its mod ; Traverse for every decimal places ; Get every fraction places when ( a * 10 / b ) / c ; Check if it is equal to the required integer ; Mod the number ; Driver function
import java . util . * ; import java . lang . * ; public class GfG { public static int first ( int a , int b , int c ) { a %= b ; for ( int i = 1 ; i <= b ; i ++ ) { a = a * 10 ; if ( a / b == c ) return i ; a %= b ; } return - 1 ; } public static void main ( String argc [ ] ) { int a = 1 , b = 4 , c = 5 ; System . out . println ( first ( a , b , c ) ) ; } }