Arrays 2 D
Arrays 2 D
0 1 2 3
0
1
2
reviewer
1 7 9 4 8
2 6 9 3 7
int sum = 0;!
!sum += rating[_____][____];!
row 3!
}!
rating[row].length > 3) {!
! if (_____________________
3 5 7 9
row 3!
sum += rating[_____][_____];! 4 2
count++;!
}! 5 7 8 6
}!
6
if (count > 0) {!
System.out.println((double) sum / count);!
}!
null
Macy’s
CVS
null
Summer 2010 15-110 (Reid-Miller) 15
Example 4
• Print the total value of the gift cards for each family
member (rows): printValueOfRows(family); !
GiftCard[][]! data) {!
public static void printValueOfRows(______________
data.length
for (int row = 0; row < __________________; row++) {!
0.0!
double total = ___________; // find total for the row!
data[row].length col++) {!
for (int col = 0; col < ___________________;
null
if (data[row][col] != ___________) {!
total += data[row][col].getBalance();!
}!
}!
System.out.println(“Row “ + row + “: $“ + total);!
}!
}!
Summer 2010 15-110 (Reid-Miller) 16