There is another problem even you rule out case for i==j
Try to set howManyBalls to 3 and following the loop.
Write down what you were asking the computer to do.
And you will find out what is the problem.
After you figure out the problem, then check out my previous suggestion for the double loop.
You need to figure out by yourself!
Surely if i = 2 then j will never have a value of 0 or 1?
The collision between 0-1 and 0-2 should have been processed when outer loop i=0, right? :D