
Failing to initialize the row
processing variables before
each row is a logic error
and will generate incorrect
results.
COMMON ERROR
TRAP
9.3 Aggregate Two-Dimensional Array Operations 589
28 }
29 // print total for row
30 System.out.println( "The total for " + months[i] + " is "
31 + priceFormat.format( currentMonthTotal ));
32 }
33 }
34 }
EXAMPLE 9.6 Processing Each Row in a Two-Dimensional Array
Again, the rows correspond to the months, and we declare and initialize at line
17 a String array named months in order to make the output user-friendly.
To calculate the total of the family cell bills for each month, we use nested
for loops at lines 21–32, following ...