Digit Sum Recursion

Hackerrank Recursion Problem

Problem Link

Here is the solution in java 8

1
2
3
4
5
6
7
8
9
// Complete the superDigit function below.
    static int superDigit(String n, int k) {
        n = n.chars().mapToLong(Character::getNumericValue).sum()*k+"";
        if(n.length() == 1) return Integer.valueOf(n);
        else return superDigit(n,1);

    }

Comments