Friday , April 28 2017
Home / java programs / Java Program for Reverse Of Number

Java Program for Reverse Of Number

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

About chandrashekhar

Hi Folks, you have reach this so far, that shows you like what you are learning. Then why don't you support us to improve for bettor tutorials by leaving your valuable comments and why not you keep in touch with us for latest updates on your favorite blog @ facebook , twitter , Or Google+ ,

Check Also

Java Program to Print Diamond Pattern

Here we are going to write a java program to print Diamond Pattern using numbers.

Leave a Reply

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