Proxy > Gmail Facebook Yahoo!

36. Given a number, write a program using while loop to reverse the digits of the number.



import java.util.*;

public class ReverseNo {

    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        System.out.print("Enter Number which you want to reverse:");
        int num = scan.nextInt();
        int revNo = reverseNumber(num);
        System.out.println("Reverse No:" + revNo);

    }

    public static int reverseNumber(int num) {
        int revNo = 0;
        while (num > 0) {
            revNo = revNo * 10 + num % 10;
            num = num / 10;
        }
        return revNo;
    }
}


Responses

0 Respones to "36. Given a number, write a program using while loop to reverse the digits of the number."


Send mail to your Friends.  

Expert Feed

 
Return to top of page Copyright © 2011 | My Code Logic Designed by Suneel Kumar