am trying to find four of a kind in a five-card poker hand. but it's not working and couldn't figure out why.
public boolean hasFourOfaKind(String hand) {
int counter = 0;
char x = 0;
for (int i = 0; i < hand.length(); i++)
{
if (i == 0) {
x = hand.charAt(0);
} else if (x == hand.charAt(i)) {
counter++;
}
}
if (counter >= 4) {
return true;
} else {
return false;
}
}
the same problem here am trying to check whether the given four-card hand is a badugi
public boolean hasFourCardBadugi(String hand) {
int diffcounter = 0;
char badugi = 0;
for (int i = 0; i < hand.length(); i++) {
if (i == 0) {
badugi = hand.charAt(0);
} else if (badugi != hand.charAt(i)) {
diffcounter++;
}
}
if (diffcounter >= 10) {
return true;
} else {
return false;
}
}