math - Summing a number's digits in Java -


this question has answer here:

let's have integer '75'. normally, in head, can add '7' '5' in order '12'. split number '75' 2 different numbers 7 , 5 add them together. leads question, how can perform in java? there math method you?

you can use plain maths

int = 75; int = / 10; // 7 int b = % 10; // 5 int c = + b;  // 12 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -