Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program called RandomTenYourLastName.java . Using a for loop and Math.random, initialize an array with ten random integers between 1 and 50. Then,

Write a program called " RandomTenYourLastName.java". Using a for loop and Math.random, initialize an array with ten random integers between 1 and 50. Then, print these eight lines of output:

  1. Every element in the array
  2. All elements in reverse order
  3. First element
  4. Last element
  5. Every element at an odd index
  6. Every odd 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() * 50);
  • As a reminder: If the remainder when you divide by 2 is 0, it's even. % is the operator to get a remainder.
  • Use an enhanced for loop to print every element in the array (Item #1 above).
  • Create two methods - one for determine the highest element and one for determining the lowest element. Pass the array as the parameter - do not create a global array. Just remember to print in the main method only!
  • Create a tester file to test the two methods you have created.

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

Students also viewed these Databases questions

Question

The paleolithic age human life, short write up ?

Answered: 1 week ago