Lesson 17 of 34

2D Arrays: Matrices

10 min 30 XP

A 2D array is a table with rows and columns, accessed as m[row][col]. m.length is the number of rows and m[0].length the number of columns.

Example: edit me and press Run

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.

Transpose: put m[r][c] into t[c][r]. A popular matrix interview question.

Challenge

+30 XP

Read r and c (rows and columns), then the matrix. Print the sum of each row on its own line. Input: 2 3 1 2 3 4 5 6 Output: 6 15

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.