For positive numbers , X must be placed at the last index where it is smaller than N [ i ]
for ( int i = number . length ( ) - 1 ; i >= 0 ; -- i ) { if ( ( number . charAt ( i ) - 48 ) > x ) { position = i ; } } }