Write a program to reverse a number

public class NumberReverse{
     public static void main(String args[]){
        int num = 123;
        int reverseNumber = 0;
        while(num > 0)
        {
            reverseNumber = reverseNumber * 10 + num % 10;
            num = num / 10;
        }
        System.out.println("Reverse of the Number - " + reverseNumber);
        
     }
}

Output: –

Reverse of the Number - 321

Leave a Reply

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