Reverse number in java

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.

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *