Question: I am having trouble finding pairs in a string of size five. So therefore, there can only be two pairs. For every pair that I have found, I should increase the score by 2 points.
Here is what I have so far, but it is incorrect.

```
  String  temp = "4 5 4 3 3";
  String  tempLine = temp.replaceAll(" ", "");
  String[]  hand = temp.split(" ");
        for(int i = 0; i < hand.length; i++)
                  {

                      if(hand[i].equals(tempLine.substring(0, 1)) && i !=0 )
                          score += 1;
                      if(hand[i].equals(tempLine.substring(1, 2)) && i != 1 )
                          score += 1;
                      if(hand[i].equals(tempLine.substring(2, 3)) && i!= 2 )
                          score += 1;
                      if(hand[i].equals(tempLine.substring(3, 4)) && i!= 3)
                          score += 1;
                      if(hand[i].equals(tempLine.substring(4)) && i != 4)
                          score += 1;

                  }

```

**EDIT: I am trying to find pairs in the hand that have similar value, for example 4 would be one pair found in this hand**

Answer: 
I think this fits what you're trying to do.

```
char[] hand = {'a','b','c','b','c'};
/* sort the hand to ensure pairs are next to each other */
for(int x=0;x<hand.length - 1;x++){
    for(int y=(x+1);y<hand.length;y++){
        if((int)hand[x] > (int)hand[y]){
            char temp = hand[y];
            hand[y] = hand[x];
            hand[x] = temp;
        }
    }
}
int score = 0;
for(int x=0;x<hand.length - 1;x++){
    if(hand[x] == hand[x + 1]){
        score++;
        /*if you want to make sure you only get pairs
          add an "x++;" that way it'll skip over the 
          letter you just tested*/
    }
}

```
This example below is one possibility of how to count pairs. The question is how it should behave (increase the score) in case there are three equal values in the string or array or whatever. Shall this be counted as three pairs or not at all...?

```

123 is in fact three combinations 12 && 13 && 23
111 is in fact three combinations 11 && 11 && 11

```

```

package edu.harris.pairs;

public class FindPairs {

  public static void main(String[] args) {
    String s = "hello";
    int score = 0;
    for (int i = 0; i < s.length() - 1; i++) {
      for (int j = i + 1; j < s.length(); j++) {
        if (s.charAt(i) == s.charAt(j)) {
          score++;
        }
      }
    }
    System.out.println(score);
  }

}

```

Hope this helps a bit.