Question: This is java and please must follow the instruction and must put //(comment) and make simple program. Thank you 4. In section 7.3 of you
This is java and please must follow the instruction and must put //(comment) and make simple program. Thank you
4. In section 7.3 of you text, there is a program on pages 325 and 326 called LargestInArray.java. For this problem you will modify this program to find both the largest value (the code is already written) and the smallest value (this is the code you will write). Add the necessary code to show both the largest and the smallest values.



7.3 Common Array Algorithms 325 Now inputs is a partially filled array, and the companion variable currentSize is set to the number of inputs. However, this loop silently throws away inputs that don't fit into the array. A bet- doublei hile Cin.hasNaxtDouble) array to hold all - now doublo [INITIAL SIZE ter approach is to grow the nputs. Grow the array if it has been completely filled if (currentSize-inputs.langth inputs-Arrays.copyof (inputs, 2inputs.langth)Grow the inputs array irputs[currentSize]-in.nextloubleO currentSiza+ When you are done, you can discard any excess (unfilled) elements: inputs-Arrays.copyofCinputs, currantSiza): The following program puts these algorithms to work, solving the task that we set our- selves at the beginning of this chapter: to mark the largest value in an input sequence. sectlon 3/LargestinArray Java l import java.util.Scarner 3/ 4 This program reads a sequence of values and prints them, marking the largest value 6 public class LargastInArray 8public static oid ninString args) 10 final int LENGTH-100 double[I values maw double[LENGTH] int currentSiza -0; 12 13 14 15 16 17 18 19 20 21 I/ Read inputs Systom.out.printInC Please enter valuas, Q to quit: Scannar in-naw while (in.has Nax tDloubleo&¤tSize
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
