samedi 20 octobre 2018

Please help sorting this array into ascending order

I would like to generate an array of 100 numbers and find their average and sum. I am able to do this but I am NOT able to get the output of numbers into ascending order! I am super new to java so any help would be awesome.

    import java.util.Random;

    public class randomNumberGen
 {
public static void main(String [] args)
{
    Random r=new Random();
    double sum = 0; // is double so to prevent int division later on
    int amount = 100;
    int upperBound = 100;

    for (int i = 0; i < amount; i++){
        int next = r.nextInt(upperBound) + 1; // creates a random int in [1,100]
        System.out.println(next);


        sum += next; // accumulate sum of all random numbers
    }

    System.out.println("Your average is: " + (sum/amount));
    System.out.println("Your sum is: " + (sum));        
}

}




Aucun commentaire:

Enregistrer un commentaire