Sunday, October 21, 2012

Java program to find reverse of a number


import java.io.*;
class reverse
{
  int num,temp,p;
  reverse(int a)
  {num=a;
    temp=num;
    p=0;}
  void findreverse()
   { while(temp>0)
        {p=p*10+temp%10;
          temp/=10;}
    System.out.println("Reverse of "+num+" is "+p);
  }
  public static void main(String s[])throws IOException
  {
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Enter the number to reverse");
    int n=Integer.parseInt(br.readLine());
    reverse r=new reverse(n);
    r.findreverse();
  }
}


Output

No comments:

Post a Comment