CodeNinja90
10/10/2019 - 12:36 AM

Reverse Number

public class ReverseNum {

    public static void main(String[] args) {

        int num = 1234 , rev = 0;

        while (num != 0){

            int digit = num % 10; // get the digit

            num = num/ 10; // Remove the digit from the number

            rev = rev * 10 + digit;  // Move the rev by a place and add the number
        }

        System.out.println("The Reversed numbers: "+rev);
    }
}