Search code examples
javaarrayspoker

Java poker hand evaluator to not working


I'm trying to figure out how to pass this but actually be working. I am afraid I'm getting false positives.

public static boolean hasPair(Card[] cards) {
     Card[] pair= new Card[5];
     for(int i=0; i<5; i++)
     {
       for(int j=i+1; j<5; j++)
       {
         if(pair[i].equals(cards[j]))
           return true;
       }
      }
    return false;

i updated to this. Is it right or am i wrong again? This is driving me nuts but im still trying i just will not sleep for the next two days.

I'm not allowed to use collections either so that kinda stinks. heres my Junit

public void testhasPair(){

         Card[] pair= new Card[5];

                pair[0]=new Card(5,1);
                pair[1] = new Card(1,1);
                pair [2]=new Card(1,2);
                pair [3]=new Card(3,3);
                pair [4]=new Card(6,3);
            assertTrue(PokerHandEvaluator.hasPair(pair));

Solution

  • Either use, or just read and learn from, one of the many poker libraries out there. There's a good list here: http://www.codingthewheel.com/archives/poker-hand-evaluator-roundup