Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int sumOfDigits(int n){
- int total = 0;
- for(int i = (int) Math.pow(10.0, Math.floor(Math.log10(n))); i >= 1; i /= 10) {
- int temp_n = n; n = n % i;
- total += Math.floorDiv(temp_n, i);
- }
- return total;
- }
Advertisement