Ok I need to make a program that will output 20 random numbers and the average of those 20 numbers. The numbers are in between 1 and 40.
So in my code below I have it set up using a for loop and I want it to stop when counter is equal to 20 this does not work when I run the program it only out puts 1 random number I dont understand why it wont output mmore than once?
Would I have to use a do while loop for this to work correctly?
Thank you any help is welcomed.
Quote:
class RandomLoops
{
public static void main (String args [])
{
int num = 0;
int average = 0;
final int NUM_RANGE = 40;
final int MIN = 1;
for (int counter = 0; counter < 20; counter++)
num = (int)(Math.random () * NUM_RANGE) + MIN;
System.out.println ("Random number is " + num);
}
}