Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

3rd Edition

0471418455, 978-0471418450

More Books

Students also viewed these Databases questions