We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
My code seems to work in Eclipse but it turns wrong in the test cases
publicstaticintsuperDigit(Stringn,intk){// Write your code hereBigIntegersuperDigit=newBigInteger(n);StringBuildersb=newStringBuilder();for(inti=0;i<k;i++){sb.append(n);}n=sb.toString();char[]superDigitCharArray;while(superDigit.compareTo(newBigInteger("10"))!=-1){intsum=0;superDigitCharArray=n.toCharArray();for(charc:superDigitCharArray){sum+=Character.getNumericValue(c);}superDigit=newBigInteger(sum+"");n=superDigit+"";}returnsuperDigit.intValue();}
Recursive Digit Sum
You are viewing a single comment's thread. Return to all comments →
My code seems to work in Eclipse but it turns wrong in the test cases
I see it now, you are supposed to make it with recursion.