Ad
  • Default User Avatar
  • Custom User Avatar

    Author note: I made the length variable because it made the return statements slightly less complicated. In the past, I probably would have created a variable to hold the String that I am returning as well, but based on what I've been seeing on this site thus far, I thought perhaps just having the return statements create the Strings they are returning might be the preferred approach. Any opinions on one approach or the other?

  • Custom User Avatar

    Author comment: How bad should I feel that I had to Google a bunch of stuff to work this one out? I figured out from my old Calc2 notes that it was a harmonic series, but then I had to look up how to sum it. I also had to look up the best way to get two decimal places that are rounded correctly. I have a feeling in the real world having to Google things is pretty common, but I suppose I would have been stuck if I got this as an interview question.

  • Custom User Avatar

    Nice work! I didn't think to just have the while loop go as long as the digit is greater than 9. That's a good way to have it stop when you've reached a single digit sum. I also like how you just used n for everything. I made some new variables that I now realize weren't needed.

  • Custom User Avatar

    And here I was so proud of my 18 line solution on this, my very first Kata... haha