Nth natural number after removing all numbers consisting of the digit 9 | Java program for the above approach ; Function to find Nth number in base 9 ; Stores the Nth number ; Iterate while N is greater than 0 ; Update result ; Divide N by 9 ; Multiply p by 10 ; Return result ; Driver Code
import java . util . * ; class GFG { static long findNthNumber ( long N ) { long result = 0 ; long p = 1 ; while ( N > 0 ) { result += ( p * ( N % 9 ) ) ; N = N / 9 ; p = p * 10 ; } return result ; } public static void main ( String [ ] args ) { int N = 9 ; System . out . print ( findNthNumber ( N ) ) ; } }