Created
April 22, 2016 16:56
-
-
Save booknara/404f7bc9027c83d99e8da0f951897bbc to your computer and use it in GitHub Desktop.
Add each digit number until the sum value is less than 10
This file contains hidden or 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
| /** | |
| * Created by Daehee Han(@daniel_booknara) on 4/21/16. | |
| */ | |
| public class AddDigits { | |
| public static void main(String[] args) { | |
| int value = 38; | |
| System.out.println(addDigits(value)); | |
| } | |
| public static int addDigits(int num) { | |
| while (num >= 10) { | |
| int sum = 0; | |
| while(num != 0) { | |
| int digit = num % 10; | |
| num = num / 10; | |
| sum += digit; | |
| } | |
| num = sum; | |
| } | |
| return num; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment