Ad
  • Custom User Avatar

    It's better to use Long#parseLong instead of Long#valueOf. That's because parseLong method returns long and valueOf method wraps the result in Long class, then the method unwraps it (which obviously is redundant).

  • Custom User Avatar

    mikiPP, I know this solution is old, but still some people try to solve this kata, they fail and after unlocking the solutions they see code like this which obviously is a bad source of knowledge.

    Anyway, good to hear you've learned how to correctly compare two strings. :D

  • Custom User Avatar

    Katya, "==" operator tests whether two values are the same object and equals() method checks if values of these objects are the same.

    If you want to know more about it, I highly recommend reading this thread: https://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java

  • Custom User Avatar

    You are trying to declare an int variable with a double value, which obviously won't work.
    However, in this case it works, because compilator knows that the type of sum variable is int and it just casts it to int. Since the result of pow is an integer (double), nothing special happens, but if the result were a non-integer, then the decimal part of the method's result would be truncated (100.18 would be 100, 11.254 would be 11, 1.0 would be 1, and so on, and so on...).

    I know this comment is 7 months old, but I wanted to clear it up.

  • Custom User Avatar

    In this case, using "==" to compare two strings is fine, but generally you should avoid it.