// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
public class AddDigits2 {
    public static void main(String[] args) {
        int number = 199;
        int result = calculateSum(number);
        System.out.println("Single digit by adding all the digits of a number repeatedly : " + result);
    }
    public static int calculateSum(int ans) {
        int result = sum(ans);
        return result < 10 ? result : calculateSum(result);
    }
    public static int sum(int ans) {
        return ans < 10 ? ans : (ans % 10) + sum(ans / 10);
    }
}
