Can anyone explain to me how to reverse without using an integer array or string? , But really understand why not + input% 10 and redistribute it again.
while (input! = 0) {reverse = no * = 10 + input% 10; Input = input / 10; }
And how to use this sample code to reverse only the weird number. Example I got this input 12345, then it will turn this weird number into output 531.
I'm not clear about your odd number as the code works (this There is no Java-specific algorithm) Example input = 2345 for the first time while loop rev = 5 input = 234 second time rev = 5 * 10 + 4 = 54 input = 23 for the third time rev = 54 * 10 + 3 input = 2 fourth time rev = 543 * 10 + 2 Input = 0
Then the number mentioned is 5432. If you want only the weird number in reverse number then the code is:
while (input! = 0) {last_digit = input% 10; If (last_decision% 2! = 0) {reversed = reverse pneumatic * 10 + final_decision; } Input = input / 10; }
Comments
Post a Comment