Created
August 6, 2017 12:33
-
-
Save kimki1124/9adeb326ce234b9f0f21d2a384e79829 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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