Ad
  • Default User Avatar

    I had the same type of solution but used do { ... } while (n != 0);
    Then if n == 0, the loop will still run at least once.

    Also note, this type of solution can do a reasonable thing negatives if you keept track of the sign: -1234 goes to -14916.

    Finally, the integer parseInt will throw appropriately if there is integer overflow.