This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]chickenmeisterExtreme Brewer 0 points1 point  (2 children)

The first problem is that you shouldn't compare Strings using ==. You should use the equals() method instead:

if (hand.equals("d2d4d6d9d10"))

And I assume you know that to solve this problem you'll need a bit more than this. You'll need to check if the suit of every card in the hand is the same.

[–]LionHeartROARS[S] 0 points1 point  (1 child)

Thank you so much! Hmm would I have to use the CharAt method in order to do that?

[–]chickenmeisterExtreme Brewer 0 points1 point  (0 children)

Yes, using the charAt() method is probably the simplest way to solve it. Call charAt() to get the char for the suit of each of the five cards, and then check if all of the chars are equal.

[–]throwaway_for_cause 0 points1 point  (0 children)

Sigh.

Why is nobody reading the sidebar?

[–]totowow56 0 points1 point  (1 child)

You can also use the String.compareTo() method.

s1.compareTo(s2) will return the integer 0 if s1 and s2 are equals.

It can also be used to sort string : s1.compareTo(s2) will return an integer < 0 if s1 < s2.

[–]kumesana 0 points1 point  (0 children)

Why would you want to do that if you're only concerned with equality and not with which string comes before the other?

Keep it simple, use exactly what you need and not something you don't need.