vendredi 7 octobre 2016

How to average random numbers in java?

thanks in advance for any help I'm in an intro to java class and our home work was to generate 10 random numbers between 1&50 which I got and then average the generated numbers. I can't figure out how to average them here's what I have. Is there a way to store each random number as a variable?

import java.util.Random;

public class randomNumberGen
{
     public static void main(String [] args)
     {
         Random r=new Random();

         for (int i=1;i<=10;i++){
             System.out.println(r.nextInt(50));
             System.out.println();
              int average = (i/4);

              System.out.println("your average is"+average);

         }
     }
}




Aucun commentaire:

Enregistrer un commentaire