Sunday 12 August 2012

Java Program- To Reverse a Number


Public Class ReverseNo
{
   public static void main(String args[])
   {
      int no= Integer.ParseInt(args[0]);
      int rev = 0;
 
       while( no != 0 )
      {
          rev = rev * 10;
          rev = rev + no%10;
          no = no/10;
      }

      System.out.println("Reverse of the given number is "+rev);
   }
}

No comments:

Post a Comment