Skip to content

Instantly share code, notes, and snippets.

@booknara
Created April 22, 2016 16:56
Show Gist options
  • Save booknara/404f7bc9027c83d99e8da0f951897bbc to your computer and use it in GitHub Desktop.
Save booknara/404f7bc9027c83d99e8da0f951897bbc to your computer and use it in GitHub Desktop.
Add each digit number until the sum value is less than 10
/**
* 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