Question: Using the following code as a starting point, finish adding the needed methods and then add two new methods. The first method call of findLowestValue(nt[]):int
Using the following code as a starting point, finish adding the needed methods and then add two new methods. The first method call of findLowestValue(nt[]):int will be inserted after the first printArray() call. The second method call of findHighestValue(int[]):int will be inserted after the sortIntArray() call. Save the values for the lowest and highest values and display them to the user after the sorted array is displayed.
Note: your are to find the most efficient algorithm for each of the searches within the constraints that I have given. The searches must be done in the order and where I have stated.
private static Scanner keyboard = new Scanner(System.in);
/** * @param args * precondition: a Scanner object for the System.in stream must exist and its reference sored in the variable keyboard. * Postcondition: a sorted integer array * Algorithm: * START * INT arraySize * INT[] myArray * STRING userResponse * REPEAT * PROMPT user for array size * Get array size and store into arraySize * CALL buildIntArray(arraySize) and store the resulting reference into myArray * CALL printArray(myArray) * CALL sortIntArray(myArray) * CALL printArray(myArray) * PROMPT user "Do you want to do this again?" * GET userResponse * UNTIL userResponse == "no" * STOP */ public static void main(String[] args) { String yesNo = ""; int arraySize = 0; int[] myArray = null; do { System.out.println("Please enter the size of the array you want."); do { System.out.println("The size must be greater than 1."); arraySize = keyboard.nextInt(); } while (arraySize <= 1); myArray = buildIntArray(arraySize); printArray(myArray); sortIntArray(myArray); printArray(myArray); yesNo = repeatProcessQuery(); } while (yesNo.equals("yes"));
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
