Find the Nth digit in the proper fraction of two numbers | Java implementation of the approach ; Function to print the Nth digit in the fraction ( p / q ) ; To store the resultant digit ; While N > 0 compute the Nth digit by dividing p and q and store the result into variable res and go to next digit ; Driver code
class GFG { static int findNthDigit ( int p , int q , int N ) { int res = 0 ; while ( N > 0 ) { N -- ; p *= 10 ; res = p / q ; p %= q ; } return res ; } public static void main ( String args [ ] ) { int p = 1 , q = 2 , N = 1 ; System . out . println ( findNthDigit ( p , q , N ) ) ; } }