```
public class Solution {
public int addDigits(int num) {
int d = 1;
int[] s = new int[11];
int i = 0;
for(i = 10; i >= 0; i--){
d = (int)Math.pow(10,i);
s[10-i] = num / d;
num -= d*s[10-i];
}
int r = 0;
for(i = 0; i <=10; i++){
r += s[i];
if (r >= 10){
r -= 9;
}
}
return r;
}
}
```