Blossomforth

int sumOfDIgits(int n)

Mar 2nd, 2017
274
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.23 KB | None | 0 0
  1. int sumOfDigits(int n){
  2.     int total = 0;
  3.     for(int i = (int) Math.pow(10.0, Math.floor(Math.log10(n))); i >= 1; i /= 10) {
  4.         int temp_n = n; n = n % i;
  5.         total += Math.floorDiv(temp_n, i);
  6.     }
  7.     return total;
  8. }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment