// 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 AddDigits {
    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 = Integer.toString(ans).chars().map(c -> c - '0').sum();
        return result < 10 ? result : calculateSum(result);
    }
}
