textXPosition = 0 ; // initialise position of text
textYPosition = 50 ;
sum = 0.0 ; // initialise sum to zero
// define an int, count, and initialise it to one. Repeat the for
// loop until count = 10, and increment count by one each time
// round the loop.
for (int count = 1 ; count <= 10 ; count++)
{
// get a value for the random number
randomNumber = (int) (Math.random() * 100) + 1;
// add the random number to sum
sum = sum + randomNumber ;
// write the random number
g.setColor(Color.blue);
g.drawString("" + randomNumber, textXPosition, textYPosition);
// increment postion coordinates
textXPosition = textXPosition + 30 ;
}
// calculate average
average = sum / 10 ;
g.drawString("The average of these numbers is: " + average, 0, 100) ;