Ad
  • Default User Avatar

    One alternative to the magic-number-conversion would be to use Character.digit(). And some more nitpicking: The import for IntStream is not necessary.

    Other than that I agree that this is the best solution I've seen here (after my own of course ;) ).

  • Default User Avatar

    Yes, I really appreciate the sumDigits method. One of the first solutions I've found that doesn't explicitly convert a char to a String just to then convert to an int. Only problem here is no exception will be thrown if something other than a number character is passed in but that could be handled easily with a quick check on the "c" variable. Thanks!