You can do this with mathematical operations that are way faster and simpler. Example in C#:
intnumber=-321;// Numberintsign=Math.Sign(number);// Signnumber*=sign;// Absintn=0;// Accumulatordo{/* '* 10' moves the accumulator the the left to accumulate one more digit.
* Then, '% 10' extracts the last digit */n=n*10+number%10;}while((number/=10)>0);// '/ 10' removes the last digitn*=sign;// Add the sign to the already reversed number
So, with -321:
Take the sign (-) and the abs (321).
The accumulator is 0.
Move left: n * 10 = 0. Digit: number % 10 = 1. Remove: number / 10 = 32.
Move left: n * 10 = 10. Digit: number % 10 = 2. Remove: number / 10 = 3.
Move left: n * 10 = 120. Digit: number % 10 = 3. Remove: number / 10 = 0.
Then, we have 321 and multiply by the sign(-) and have -123.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
You can do this with mathematical operations that are way faster and simpler. Example in C#:
So, with -321: