String[][] words = new String[3][4]
int[][] array = { {1,2,3,-5}, {3,5,-1,2}, {-2,7,5,3} };
//do some set up first for (int row = 0; row < matrix.length; row ++) { for (int column = 0; column < matrix[0].length; column++) { //do something with each element: matrix[row][column] } }
Record your participation in Piazza clicker question Lesson18 Q1
We are going to do some 2d array processing. Download this starter file.
IntArray2DProcessor
to see what is thereIntArray2DProcessor
, we want to complete the method that finds the sum of all the elements in the 2D arrayRecord your participation in Piazza clicker question Lesson18 Q2
We can use basically the same loops to implement other array processing algorithms
IntArray2DProcessor
? Think about what you need to change.max
method
Record your participation in Piazza clicker question Lesson18 Q3
What if we wanted to process only one row in IntArray2DProcessor
?
IntArray2DProcessor
to find the sum of the elements in the rth row
public int sum(int r)
matrix[r][column]
Record your participation in Piazza clicker question Lesson18 Q4
Given an 8 × 8 array for a board game:int[][] board = new int[8][8];
Finish the main method in the Board class and use nested loops to initialize the board so that zeros and ones alternate, like this
0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0
0 1 0 1 0 1 0 1
. . .
1 0 1 0 1 0 1 0
Record your participation in Piazza clicker question Lesson18 Q5
Add code to the main method of the Board class in the previous activity to print the board.