Making an int count up from 0 to 100, then back down from 100 to 0?

So, I have some h/w where we're given a program of a bouncing ball. The ball bounces around in a window hitting the edges and bouncing off, and it also gradually increases in size randomly:

if (rand.nextDouble() < 0.1) ballSize++;

Pretty simple, I guess. The ballSize is an int set at 10, and it gradually gets bigger infinitely. We're supposed to cap it to an arbitrary number, and while I can manage to make it stop increasing at a certain int, I can't figure out how to reverse the operation and have it start counting back down. All I could think of something like:

if (ballSize == 100) ballSize--;

But obviously that won't keep making it decrease. Can anyone try and lead me to the right direction?

Replies To: Making an int count up from 0 to 100, then back down from 100 to 0?

Re: Making an int count up from 0 to 100, then back down from 100 to 0?

Posted 06 October 2012 - 01:21 PM

Think about using a boolean to trigger a decrease in size. When the ball hits size n, invert the boolean. Then based on the boolean's value, either add or subtract the changeInSize constant from the ballSize.