KayterNater
KayterNater

Reputation: 43

I need to generate a sequence of 20 random values between 0 and 99 in an array

I need to generate a sequence of 20 random values between 0 and 99 in an array. I need to print the sequence, sort it, and print the sorted sequence. Here is what I have so far.

import java.util.ArrayList;
import java.util.Random;
import java.util.Arrays;

public class  Loop20{

    public static void main(String[] args) {

        Random random = new Random();
        int array[]=new int[20];
        System.out.println("The Random Numbers are: ");
        for (int i=0; i < array.length ; i++) {
            array[i] = random.nextInt(99);
            System.out.println(array[i]);            
        }    

    }
}

Thank-You!

Upvotes: 2

Views: 2352

Answers (1)

Walls
Walls

Reputation: 4010

After you fill the array with the random numbers, run some sort of sorting function (your choice) on it.

Lastly, have another for loop that is the printing piece, which looks really similiar to what you have in the other for loop.

Hope that helps without just giving you a code block that does it, it lets you have some fun looking up some of the pieces :)

Upvotes: 1

Related Questions