Question: Make a program using Java that asks the user to input an integer. That integer makes and prints out an evenly spaced, size by size

Make a program using Java that asks the user to input an integer. That integer makes and prints out an evenly spaced, size by size 2D array (If odd numbers like 7 is used, only columns 0-6 should be filled with numbers so there can be a middle index). The array must be filled with random numbers less than 100. Then, using recursion find a "peak" using the following algorithm.

1. Find the largest element in the middle column (ex: 7 is input ---> first rec. call ---> array index starts at left 0 right 7 ---> 0 left 6 right so there is a middle index)

2. Check to see if a value that is to its immediate left, right, up, or down is larger than itself. (ex:second rec call---> value to left is bigger ---> left is 0, right is 3)

3. If it is, move to that number and repeat until no numbers are directly next to a bigger number.

4. print out the peak (ex: 91 is a peak at row 0, col 2)

//Following may be useful

Make a program using Java that asks the user to input an

integer. That integer makes and prints out an evenly spaced, size by

Generalize this algorithm and implement the recursive method: public static int[] findPeakRec(int[][] data, int left, int right) Hint: You may also find it helpful to write helper method(s). For example, you may want: public static int largest (int[] [] data, int col) // (returns the index (row) of the largest element in the given column in the data table) Your main should look something like this /I code to read in size from user int[] data -getRandomDataTable (size)// helper method // assume data is the example array from above printDataTable (data) // helper method // Call recursive method to find peak int[] peakCoords - findPeakRec (data, 0, size); // Get the peak value from the data using the coords returned int peakVal-data [peakCoords [0]] [peakCoords [1]1; /I output the peak and its location System.out.println (peakVal " is a peak at row "+ peakCoords [0] + ", col"+ peakCoords [1]) Generalize this algorithm and implement the recursive method: public static int[] findPeakRec(int[][] data, int left, int right) Hint: You may also find it helpful to write helper method(s). For example, you may want: public static int largest (int[] [] data, int col) // (returns the index (row) of the largest element in the given column in the data table) Your main should look something like this /I code to read in size from user int[] data -getRandomDataTable (size)// helper method // assume data is the example array from above printDataTable (data) // helper method // Call recursive method to find peak int[] peakCoords - findPeakRec (data, 0, size); // Get the peak value from the data using the coords returned int peakVal-data [peakCoords [0]] [peakCoords [1]1; /I output the peak and its location System.out.println (peakVal " is a peak at row "+ peakCoords [0] + ", col"+ peakCoords [1])

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!