You are viewing a single comment's thread. Return to all comments →
With recursion in Java. I don't understand the objections to recursion. It is good practice for logical thinking.
static int superDigit(String number, int k) { if (number.length() > 1) { long sum = 0; for (int i = 0; i < number.length(); i++) { sum += Character.getNumericValue(number.charAt(i)); } return superDigit(Long.toString(sum * k), 1); } else return Character.getNumericValue(number.charAt(0)); }
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 →
With recursion in Java. I don't understand the objections to recursion. It is good practice for logical thinking.