Reverse Number Program in Java

Reverse Number Program in Java
Reverse Number Program in Java

If a number=1234, then reverse of number is 4321.


import java.util.Scanner;

public class ReverceNumber
{
    public static void main(String[] args)
    {
        // TODO code application logic here
        int n, num, r,
        rev = 0;
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter number=");
        n = sc.nextInt();
        num = n;
        while (num > 0)
        {
            r = num % 10;
            rev = (rev * 10) + r;
            num = num / 10;
        }
        System.out.println("Reverce of Number=" + rev);
    }
}

Output:

Enter number=1234
Reverce of Number=4321
b. tech. bca icse java java tutorials learn java mca programs

Frequently Asked Questions

If a number=1234, then reverse of number is 4321.
If a number=1234, then reverse of number is 4321.