You are viewing a single comment's thread. Return to all comments →
static long sum(String str){ long p = 0; for (int i=0; i < str.length(); i++) { p += Character.getNumericValue(str.charAt(i)); } return p; } public static int superDigit(String n, int k) { long p = sum(n) * k; while (p >= 10){ p = sum(Long.toString(p)); } return (int) p; }
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 →