Question: Java One common algorithm is finding the largest element in the array-that is, the array element with the largest value-as well as finding the location

Java  Java One common algorithm is finding the largest element in the

One common algorithm is finding the largest element in the array-that is, the array element with the largest value-as well as finding the location of the largest element in the array. For all sections, assume that the array contains unique values (no repetitions). We will start by finding the largest value. Initially, we assume that the first element in the list is the largest element and create a variable maxValue that is initialized to the first element in the array. We then compare the element that maxValue is storing with every element in the list. Whenever we find an element in the array larger than the element that maxValue is storing, we update maxValue so that it stores the index of the newer larger element. Algorithm ArrayLargestElement Declare and initialize maxValue to the first element in the array. Use a FOR loop to traverse the array.//You already checked the first element, so you should start the loop at the second element. If the element at this index is larger than maxValue Update maxValue Output maxValue. Write a program MyArray that declares an array (you can preload the array elements instead of using an input statement) containing the following elements: 45, 38, 27, 46, 81, 72, 56, 61, 20, 48, 76, 91, 57, 35, and 78, and outputs the largest value. Re-test your program using the following testing cases: 300, 38, 27, 46, 81, 72, 56, 61, 20, 48, 76, 91, 57, 35, and 78 45, 38, 27, 46, 81, 72, 56, 61, 20, 48, 76, 91 57, 35, and 800 Modify the program described above so that it outputs the index where the largest value is positioned. Use a variable maxindex to store the location. Include in the program described above a variable sum that, while traversing the array to find the largest element, sums up all the elements and outputs the result. At the end of the program, write a FOR loop that prints the array in reverse (you are not reversing the array; you are simply printing it in reverse order)

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!