You are viewing a single comment's thread. Return to all comments →
Java
public static int superDigit(String n, int k) { if (n.length() == 1) { return Integer.parseInt(String.valueOf(n.charAt(0))); } long sumOfDigits = 0; for (char c : n.toCharArray()) { sumOfDigits += Integer.parseInt(String.valueOf(c)); } sumOfDigits *= k; return superDigit(String.valueOf(sumOfDigits), 1); }
Seems like cookies are disabled on this browser, please enable them to open this website
Recursive Digit Sum
You are viewing a single comment's thread. Return to all comments →
Java