lundi 27 juillet 2015

Print random numbers in array size 20 and print number in lndex number

Question:

Write a program to create an array of size 20 to store integers. Then, the program should generate and insert random numbers between 1 and 7, inclusive into the array. Next, the program should print the array as output.
A simple subset is part of an array that consists of a set of 4 elements next to each other. The program will generate a random number between 0 and 19, which represents the location in the array (i.e. index number). Then, the program should print the 4 elements from that location. The program should take into consideration the boundaries of the array. There is no user input for this program.
Your program must include, at least, the following methods:
- insertNumbers, which will take as input one integer array and store the random numbers in it. - computeLocation, which will generate the location random number and return it.

A sample run of the program is shown below:

Sample output #1:
Array: 2 7 4 3 1 5 7 2 3 6 2 7 1 3 2 4 5 3 2 6
Random position: 2
Subset: 4 3 1 5

Sample output #2:
Array: 2 7 4 3 1 5 7 2 3 6 2 7 1 3 2 4 5 3 2 6
Random position: 18
Subset: 2 6 2 7




Aucun commentaire:

Enregistrer un commentaire