rss
Twitter Delicious Facebook Digg Stumbleupon Favorites

Friday, October 7, 2011

A program to reverse a given number.



class ReverseANumber{
      public static void main(String args[]){
          int num = Integer.parseInt(args[0]);               
          int remainder, result=0;
          while(num>0){
              remainder = num%10;
              result = result * 10 + remainder;
              num = num/10;
         }
         System.out.println("Reverse number is : "+result);
    }
}

1 comments:

Unknown said...

I did not get the logic.. can u explain it pls??

Post a Comment

Powered by Blogger.