Digital root recursive function
With a bit of knowledge of modular math then you can know that for numbers > 0 getDigitalRoot(n)== n%9 except when dividable by 9 then it is 9.

This simplifies the algorithm a bit.

public static int getDigitalRoot(int n) {
    if(n==0) 
        return 0;
    if(n%9 == 0) 
        return 9;
    return n%9;
}


If you still want the looped version you can do a variation; instead of using another variable to hold the result and retrying until smaller than 10 just do this:

while (num &gt;= 10) {
    num = num/10 +num % 10;
}


It works for roughly the same reason as the first modulo operation.