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

Hello world

My name is Simon Krenger, I am a Technical Account Manager (TAM) at Red Hat. I advise our customers in using Kubernetes, Containers, Linux and Open Source.

Elsewhere

  1. GitHub
  2. LinkedIn
  3. GitLab