Answered step by step
Verified Expert Solution
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:
- Every element in the array
- All elements in reverse order
- First element
- Last element
- Every element at an odd index
- Every odd element
- Highest element
- 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started