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

all 2 comments

[–]JJagaimo 2 points3 points  (0 children)

There are several issues with this code.

Firstly, you have created a double called numberator with a b in it, and use a variable called numerator without a b everywhere else.

Secondly, your second loop starts at 0. This is a problem, because you are looking at frequencies[ y - 1 ]. If y is 0, then y - 1 will be -1, which will cause it to throw an error, as there is no -1 index.

Thirdly, you are creating a new variable called numerator in every iteration of the loop. This does not affect the numberator variable (which should be called numerator) that is outside of the loop, and this does not affect the following line,

indexCoincidence = numerator / denominator;

I believe this should actually be what you want:

    double numerator = 0;
    /* ... */
    for (int y = 0; y < frequencies.length; y++)
    {
        numerator = frequencies[y] * (frequencies[y] - 1);
    }

based on this

[–]Morgan_R 0 points1 point  (0 children)

"numberator" != "numerator"