Many wrong answers here. Here's what OP wants:
Method return should be like if entered a number, suppose 345, then
output should be 3+4+5=12 --> 1+2 = 3.
This will do the job:
public static int compute(int param) {
int sum = 0;
do {
sum = 0;
while (param > 0) {
sum += param % 10;
param /= 10;
}
param = sum;
} while (sum >= 10);
return sum;
}