I have a number like 99
now I need to get a single digit number like –
9*9 = 81
8*1 = 8
ex2:
3456 3*4*5*6
360 3*6*0
What will be the efficient way to get the output beside change the number to character/string then multiply with each adjacent .
Let me make the problem little more complex , what if I want to get the number of steps required to make the N to a single digit , then recursion may loose the steps and need to be done in a single method only
Presuming those are ints, you can use division and modulus by the base (10):
For the second example, you’d want to use a
while (X >= 10)loop.