I need to build a method to add each digit of the string given in the parameter, and as long as only 1 digit is left, for example. 1234 = (1+2+3+4) = 10 = (1+0) = 1 .
At first, I thought that a recursive call or while loop should be accurate. But is there a smarter way? Is using modulo possible?
1234 % 9 = 1 It seems that this works ... But no: 9%9 not equal to 9 , but this value is 0 .
Is there a way to build this function without recursive / for / while?
source share