If str [ i ] is between 0 and 9 and i is the last occurence in str
else if ( ( str . charAt ( i ) >= '0' && str . charAt ( i ) <= '9' ) && num [ str . charAt ( i ) - 48 ] == i ) { int occ = str . charAt ( i ) - 48 ; while ( occ -- > 0 ) { res = res + str . charAt ( i ) ; } } else { res = res + str . charAt ( i ) ; } }