I can total my whole array. but now I am trying to do a total for the rows and an total for the columns. I am stuck on how I need to manipulate the code to just print by row and column seperate.
Thanks Ryan.
Suni Das
Greenhorn
Joined: Nov 27, 2001
Posts: 2
posted
0
------------------------------------------------------------ I can total my whole array. but now I am trying to do a total for the rows and an total for the columns. I am stuck on how I need to manipulate the code to just print by row and column seperate. -------------------------------------------------------------- int rowTotal = 0; int colTotal =0 ; for(int row = 0; row < sales.length; row++){ for(int col = 0; col < sales[row].length; col++){ rowTotal += sales[row][col]; } System.out.println("Row Total for the row:"+(row+1)+ " = "+rowTotal); rowTotal = 0; } for(int col = 0; col < sales[0].length; col++){ for(int row = 0; row < sales.length; row++){ colTotal += sales[row][col]; } System.out.println("Col Total for the col:"+(col+1)+ " = "+colTotal); colTotal = 0; }