Your method is very bad. You are looping through the same string multiple times.
Instead use 1 loop over the string and use an array of counters to count the digits. You should be able to reduce your loop body to 1 line of code (if you assume valid input).
|