I dont understand!!
Hey everyone i don't understand why counter < responses.length;
includes the 40th number in the array shouldn't it stop at the 39th number?
int responses [] ={1,2,6,4,8,5,9,7,8,10,1,6,3,8,6,10,3,8,2,7,6,5,7,6
,8,6,7,5,6,6,5,6,7,5,6,4,8,6,8,10};
int frequency [] =newint[11];
for(int counter = 0;counter < responses.length;++counter)
{
++frequency[responses[counter]];
}//end for loop
> You're pre-incrementing your counter variable.
>
> Change it to:
> [code]
> for(int counter = 0;counter <
> < responses.length;counter++)
> /code]
> and see how it behaves then.
Absolutely irrelevant.
++counter vs. counter++ does NOT cause the ++ to happen at a different point relative to the loop. It's simply that the value the ++counter expression is the incremented value of counter, and the value of the counter++ expression is the original value of counter. But that expression's value is not used anywhere, so it doesn't matter.