Here we are going to write a program for Reverse of Number in Java.

Reverse Of Number :


import java.util.Scanner;

public class ReverseOfANumber {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter Any Number : ");
        int input = sc.nextInt();
        doReverseOfANumber(input);
    }
    
    public static int doReverseOfANumber(int number) {
        int reverse = 0;

        String temp = "";
        if (number > 0) {
            while (number > 0) {
                temp += number % 10;
                number /= 10;
            }

            reverse = Integer.valueOf(temp);
            System.out.print("Reverse is : "+reverse);
        }

        return reverse;
    }
}

Output :

Enter Any Number : 152562
Reverse is : 265251

Happy Learning 🙂