```
public class Solution {
public int addDigits(int num) {
int sum = sum(split(num));
while (sum >= 10) {
sum = sum(split(sum));}
return sum;
}
public static int[] split(int num) {
String x = Integer.toString(num);
int[] nums = new int[x.length()];
for (int i = 0; i < nums.length; i++) {
nums[i] = num % 10;
num /= 10;
}
return nums;
}
public static int sum(int[] a) {
int res = 0;
for (int i = 0; i < a.length; i++) {
res += a[i];
}
return res;
}
```

}