I'm stuck with an exercise involving recursion
The question:
Write a recursive function which returns an integer, the "check digit". This check digit is computed by calculating the sum of all digits from the passed-in integer. However, if the result is greater than or equal to 10 (i.e., more than a single digit), then the calculation should be performed again using the result as input. And thus until the final number returned will be a single digit; this digit is the "check digit".
An Example:
With the number 869419 ----> 8+6+9+4+1+9 = 37 --> 3+7 = 10 -> 1.
*The Closest Solution I've reached : *
public static int Bik (int n) {
int sum=0;
if (n/10 == 1 || n==1) {
return 1;
}
else {
if (n%10 != 0) {
return Bik((n/10) + (n%10));
}
return (n);
}
}
public static void main(String[] args) {
System.out.println(Bik(1892));
}