//  Data Structures with Java by John R. Hubbard
//  Copyright McGraw-Hill, 2001
//  Problem 1.5 on page 20


public class Pr0105
{ public static void main(String[] args)
  { int n=1;
    while (n>0)
    { System.out.println("reverseDigits(" + n + ") = " + reverseDigits(n));
      n *= 2;
    }
  }
  
  public static int reverseDigits(int n)
  { if (n==0) return 0;
    int sign = (n<0?-1:1);
    if (n<0) n = -n;
    int reverse=0;
    while (n>0)
    { reverse = 10*reverse + n%10;
      n /= 10;
    }
    return sign*reverse;
  }
}
