Skip to content

Instantly share code, notes, and snippets.

@thmain
Created June 1, 2018 05:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thmain/eb16c0e1b5ea210538625a720a9d7b13 to your computer and use it in GitHub Desktop.
Save thmain/eb16c0e1b5ea210538625a720a9d7b13 to your computer and use it in GitHub Desktop.
public class SumOfDigits {
public static void digitsSums(int number){
int sum = 0;
int n = number;
while(n>0){
sum += n%10;
n = n/10;
}
System.out.println("Sum of digits of number " + number + " is: " + sum);
}
public static void main(String[] args) {
int number = 3045;
digitsSums(number);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment