Created
June 1, 2018 05:40
-
-
Save thmain/eb16c0e1b5ea210538625a720a9d7b13 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 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