Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
You are right. We don't need the "else" statment because the previous "returns". Also, the other friend is right too, the right way to compare string (motivations of this in other answer here) is using the .equals(). I adjusted my solution.
Also I don't like "if" clausules without curly braces, although the code will have more lines. More clear is better. I adjusted the spacements too :)
Thank you guys!
It's good solution, but why have you written else statement in the end? Programm will go to command return "green", only if current state wasn't "yellow" or "red".
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
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
You are right, but this code have a long time.I have learned it in the bad way, ty anyway!
Why to avoid?
In this case, using "==" to compare two strings is fine, but generally you should avoid it.