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
Post a Comment