Reverse number in java

Previous
Next

In this post, we will see how to reverse a number in java.

Here is simple program to reverse a number.

Output:

Enter a Number : 4567
Reverse of the number : 7654

Let’s just observe values of variables at the end of each iteration.
Iteration 0: number = 4567,remainder = 0, reversedNumber = 0
Iteration 1: number = 456,remainder = 7, reversedNumber = 7
Iteration 2: number = 45,remainder = 6, reversedNumber = 76
Iteration 3: number = 4,remainder = 5, reversedNumber = 765
Iteration 4: number = 0,remainder = 4, reversedNumber = 7654

That’s all about reversing a number in java.

Previous
Next

Join Our News Letter – Stay Updated

Subscribe to Awesome Java Content.




Add Comment

Join Our News Letter - Stay Updated

Subscribe to Awesome Java Content.
You can like our facebook page Java2blog