Question: java Using a for loop and Math.random, initialize an array with ten random integers between 1 and 20. Then, print these eight lines of output:

java

Using a for loop and Math.random, initialize an array with ten random integers between 1 and 20. Then, print these eight lines of output:

1.Every element in the array

2.Every element at an even index

3.Every even element

4.All elements in reverse order

5.First element

6.Last element

7.Highest element

8.Lowest element

Important notes:

Your program should not use magic numbers in your for loops. This means that you should use your arrayName.length to find out what the last element is. In your code, the only 10 that should be present is on the first array declaration. I should easily be able to modify your array declaration to be 11 or 12 or 32 and your program should still function.

Create and use variables in your Math.random statement. It should not be: int randNum = 1 + (int) (Math.random() * 20);

As a reminder: If the remainder when you divide by 2 is 0, it's even. % is the operator to get a remainder.

Your program should use at least one enhanced for loop.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!