Question: How does Java use for loops and while loops to search an array? A global array named array 5 2 0 has been declared and
How does Java use for loops and while loops to search an array?
A global array named array has been declared and initialized at the top of your code
Below the main method, write a NEW public static method named findMin with no parameters and it returns an
integer
It will contain a for loop that will search the global array array and return the indexsubscript of the SMALLEST
item in the array.
Below the main method, write a NEW public static method named getMax with no parameters and it returns an
integer
It will contain a while loop that will search the global array array and return the VALUE of the LARGEST item in
the array.
Understand the difference between the INDEX and the VALUE stored in the array. Look carefully at the example
below:
The smallest number in the array is if you are looking for the INDEX return a because it is in position of the
array
The largest number in the array is if you are looking for the VALUE return a not the index where it is located
Inside the main method:
Declare a local int variable named small and assign it the initial value of
Declare a local int variable named max and assign it the initial value of
Call the method named findMin and assign the return value to small
Call the method named getMax, and assign the return value to max
Print the message 'Method findMin output is plus the value in the variable small
Print the message 'Method getMax output is plus the value in the variable max
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
