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.
public static int super_Digit(String str, int k) {
int num = Integer.parseInt(str);
if (str.length() == 1) {
return num;
}
int sum = 0;
int rev = 0;
while (num != 0) {
rev = num % 10;
sum = sum + rev;
num = num / 10;
}
String newstring = String.valueOf(sum);
return super_Digit(newstring, newstring.length());
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Super Digit
You are viewing a single comment's thread. Return to all comments →
java solution
public static int super_Digit(String str, int k) { int num = Integer.parseInt(str);