D
Darkgroove
Guest
Ok I need to code a program that uses arithmetic operations to reverse an integer input by the user and display it to them.
Eg. 1234 needs to be output back to the user as 4321.
So I use the modular operation to get each digit:
1234 % 10 = 4
123 & 10 = 3
12 % 10 = 2
1 % 10 = 1
So I have the pattern 4,3,2,1. Without predefining a set number of digits for a user to enter, and without using loops, how would I display the number 4321 back to the user?
For example, I'd need to keep doing the modular of the function until the remainder is 0, but we aren't allowed to use loops. We also can't use any predefined java classes (like stringbuffer's .reverse()). Can anyone suggest some code?
Jimmy suggested using bit shifts but I can't understand it all that well and neither does he.
Eg. 1234 needs to be output back to the user as 4321.
So I use the modular operation to get each digit:
1234 % 10 = 4
123 & 10 = 3
12 % 10 = 2
1 % 10 = 1
So I have the pattern 4,3,2,1. Without predefining a set number of digits for a user to enter, and without using loops, how would I display the number 4321 back to the user?
For example, I'd need to keep doing the modular of the function until the remainder is 0, but we aren't allowed to use loops. We also can't use any predefined java classes (like stringbuffer's .reverse()). Can anyone suggest some code?
Jimmy suggested using bit shifts but I can't understand it all that well and neither does he.










