Skip to content

Instantly share code, notes, and snippets.

@kimki1124
Created August 6, 2017 12:33
Show Gist options
  • Save kimki1124/9adeb326ce234b9f0f21d2a384e79829 to your computer and use it in GitHub Desktop.
Save kimki1124/9adeb326ce234b9f0f21d2a384e79829 to your computer and use it in GitHub Desktop.
public static int digital_root(int n) {
int sum = 0;
if(String.valueOf(n).length() == 1){
return n;
}
while(String.valueOf(n).length() != 1){
sum += n % 10;
n = n / 10;
}
sum += n;
if(String.valueOf(sum).length() == 1){
return sum;
}else{
return digital_root(sum);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment