Q:

Method for calculating Full House not working

Here's my code for calculating a full house using 5 die. Now some numbers will work, such as if I roll a 1, 6, 6, 6, 1. But if I roll a 4, 4, 5, 5, 4. It will not work, and I have no idea. I know there is a lot of if statements and it could have done better, but I am a beginner programmer, and this is what I feel comfortable doing since I can't do a complex, logical algorithm. Thanks.   
        Arrays.sort(die);
        int score = 0;

        int d1 = die[0];
        int d2 = die[1];
        int d3 = die[2];
        int d4 = die[3];
        int d5 = die[4];

        if (d1 == 1)
        {
            if (d1 == 1 && d2 == 1)
            {
                if (d3 == 2 && d4 == 2 && d5 == 2)
                {
                    score = 25;
                }
                if (d3 == 3 && d4 == 3 && d5 == 3)
                {
                    score = 25;
                }
                if (d3 == 4 && d4 == 4 && d5 == 4)
                {
                    score = 25;
                }
                if (d3 == 5 && d4 == 5 && d5 == 5)
                {
                    score = 25;
                }
                if (d3 == 6 && d4 == 6 && d5 == 6)
                {
                    score = 25;
                }
            }
            else if (d1 == 1 && d2 == 1 && d3 == 1)
            {
                if (d4 == 2 && d5 == 2)
                {
                    score = 25;
                }
                if (d4 == 3 && d5 == 3)
                {
                    score = 25;
                }
                if (d4 == 4 && d5 == 4)
                {
                    score = 25;
                }
                if (d4 == 5 && d5 == 5)
                {
                    score = 25;
                }
                if (d4 == 6 && d5 == 6)
                {
                    score = 25;
                }
            }
        }
        if (d1 == 2)
        {
            if (d1 == 2 && d2 == 2)
            {
                if (d3 == 3 && d4 == 3 && d5 == 3)
                {
                    score = 25;
                }
                if (d3 == 4 && d4 == 4 && d5 == 4)
                {
                    score = 25;
                }
                if (d3 == 5 && d4 == 5 && d5 == 5)
                {
                    score = 25;
                }
                if (d3 == 6 && d4 == 6 && d5 == 6)
                {
                    score = 25;
                }
            }
            else if (d1 == 2 && d2 == 2 && d3 == 2)
            {
                if (d4 == 3 && d5 == 3)
                {
                    score = 25;
                }
                if (d4 == 4 && d5 == 4)
                {
                    score = 25;
                }
                if (d4 == 5 && d5 == 5)
                {
                    score = 25;
                }
                if (d4 == 6 && d5 == 6)
                {
                    score = 25;
                }   
            }
        }
        if (d1 == 3)
        {
            if (d1 == 3 && d2 == 3)
            {
                if (d3 == 4 && d4 == 4 && d5 == 4)
                {
                    score = 25;
                }
                if (d3 == 5 && d4 == 5 && d5 == 5)
                {
                    score = 25;
                }
                if (d3 == 6 && d4 == 6 && d5 == 6)
                {
                    score = 25;
                }
            }
            else if (d1 == 3 && d2 == 3 && d3 == 3)
            {
                if (d4 == 4 && d5 == 4)
                {
                    score = 25;
                }
                if (d4 == 5 && d5 == 5)
                {
                    score = 25;
                }
                if (d4 == 6 && d5 == 6)
                {
                    score = 25;
                }
            }
        }
        if (d1 == 4)
        {
            if (d1 == 4 && d2 == 4)
            {
                if (d3 == 5 && d4 == 5 && d5 == 5)
                {
                    score = 25;
                }
                if (d3 == 6 && d4 == 6 && d5 == 6)
                {
                    score = 25;
                }
            }
            else if (d1 == 4 && d2 == 4 && d3 == 4)
            {
                if (d4 == 5 && d5 == 5)
                {
                    score = 25;
                }
                if (d4 == 6 && d5 == 6)
                {
                    score = 25;
                }
            }
        }
        if (d1 == 5)
        {
            if (d1 == 5 && d2 == 5)
            {
                if (d3 == 6 && d4 == 6 && d5 == 6)
                {
                    score = 25;
                }
            }
            else if (d1 == 5 && d2 == 5 && d3 == 5)
            {
                if (d4 == 6 && d5 == 6)
                {
                    score = 25;
                }
            }
        }
        return score;
    }
    else
        return 0;
}

A:

Firstly — the reason that { 4, 4, 4, 5, 5 } doesn't work is that this structure:
    if (d1 == 4)
    {
        if (d1 == 4 && d2 == 4)
        {
            // ...
        }
        else if (d1 == 4 && d2 == 4 && d3 == 4)
        {
            // ...
        }
    }

will never run the second ...: the second condition is only ever satisfied in cases where the first condition was already satisfied.
The minimal fix would be to re-order those two if-blocks.
A better fix is, don't compare all these dice to fixed values, but rather, compare them to each other. You've already got Arrays.sort(die), which is a good idea. Once you've done that, you can detect a full house just by writing:
if (d1 == d5)
{
     // five of a kind
}
else if ((d1 == d2 && d3 == d5) || (d1 == d3 && d4 == d5))
{
     // full house
}

Do you see why?

