You are on page 1of 5

Two-Dimensional Arrays

Wednesday, August 14, 2019

CSCI 1302 Page 1


CSCI 1302 Page 2
CSCI 1302 Page 3
34 //sum each row
35 //move this accumulator inside the first
36 //for loop so that it can be reset each time int total = 0; //accumulator
37 for(int row = 0; row < classes.length; row++){
38 int total = 0;
39 for(int col = 0; col < classes[0].length; col++){
40 total = total + classes[row][col];

CSCI 1302 Page 4


40 total = total + classes[row][col];
41 //OR you could do it like this:
42 //total += classes[row][col];
43 }
44 System.out.println("The total is " + total);
45 }
46 //move this inside the outer for loop as well so that it can print each row's
total
47 //System.out.println("The total is " + total);

CSCI 1302 Page 5

You might also like