Docsity

CSIS 110 Lec. 29: 2D Arrays - Rows & Columns, Lab 23: Finding Max Values - Prof. Brian F. , Study notes of Javascript programming

Partial preview of the text

Download CSIS 110 Lec. 29: 2D Arrays - Rows & Columns, Lab 23: Finding Max Values - Prof. Brian F. and more Study notes Javascript programming in PDF only on Docsity!

CSIS 110 - Lecture 29

Quiz: next Wednesday Last time 2D arrays. Let's review the memory organization of a 2D array again. Let's look at TwoDim2 again

  • Let's write a method getRow to return the i'th row of the array. Check for i out of range.
  • Let's write a method getColumn to return the i'th column of the array. Check for i out of range. Key Points:
  • method can return an array.
  • method can create an array and return it.

Lab 23 Write a method getMaxByRow in class TwoDim2. This method returns a one- dimensional array – the number of elements in the one-dimensional array is the same as the number of rows in the 2D array anArray. The method should set the value of each element of the one-dimensional array to the maximum value in the corresponding row of the 2D array. For example, if the 2D array is: 10 7 19 2 -3 5 0 8 12 4 8 - Then this method should return a one-dimensional array containing 3 elements: 19 8 12 Suggested approach: Write a private method getMax( int[] row ) that returns the maximum value in a row of the two-dimensional array. Recall that each row is a one-dimensional array. Use a for loop to call this method for each row in the 2D array. Store the return value in the appropriate element of a one-dimensional array, and return this array when it is full. Use the homework submission system (link on course web site) to turn in Lab 23.