PDA

View Full Version : Resolved Adding Columns of 2dim Arrays



SChaput
10-11-2008, 09:24 PM
I have the below code figured out, however when it prints it prints out 24 values. In a perfect world i only want it to print out the total of each of the 4 columns.


double figures [][]= {{100,175,200,150},
{200,150,175,150}, //[1][0]-[1][3]
{100,50,75,100}, //[2][0]-[2][3]
{150,175,200,100}, //[3][0]-[3][3]
{120,150,175,200}, //[4][0]-[4][3]
{110,150,160,100}};//[5][0]-[5][3]
double [] qtr = new double[4];
int total1;
for (int col=0; col< figures[0].length; col++)
{
total1=0;
for(int row=0; row<figures.length; row++){
total1+= figures[row][col];
qtr[col]= total1;
System.out.println(qtr[col]);
}
}