public class Solution {

public int addDigits(int num) {

int sum = 0;

if (num == 0){

return num;

}

while(num>0){

sum = sum + num%10;

num = num/10;

}

return sum;

}

}

I know this is not an efficient answer, but it is also NOT correct? Site reported if input 10, output would also be 10, but I tried on my PC compiler, output is 1. What's wrong?