Tuesday, 23 September 2014

Program For Reverse Number


import java.io.*;
class  Reverse
{
    public static void main(String s[]) throws Exception
    {
        int n = 0,rev;
        Reverse r = new Reverse();
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        System.out.print("\nEnter no: ");
        n = Integer.parseInt(br.readLine());

        rev = r.reverse(n);

        System.out.print("\nReverse no: "+rev);
        System.out.println();
    }


    public int reverse(int num)
    {
        int reverse = 0;
        while (num != 0)
        {
            reverse = reverse * 10;
            reverse = reverse + num%10;
            num = num/10;
        }
        return reverse;
    }
}
Output

No comments:

Post a Comment