Java: Recursive digit sum function
For an university assignment, I had to implement a recursive function to calculate the digit sum of a given number. I place my solution here for my own reference:
public static int digitSum(int n) {
if(n < 10)
return n;
else
return n % 10 + digitSum(n / 10);
}
This code can also be found in the GitHub repository that I am keeping for university: ChecksumTool.java