Results 1 to 1 of 1

Thread: Adding Columns of 2dim Arrays

  1. #1
    Join Date
    Feb 2008
    Posts
    90
    Thanks
    3
    Thanked 2 Times in 2 Posts

    Default Adding Columns of 2dim Arrays

    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.
    Code:
    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]);
            }
          }
    Last edited by SChaput; 10-11-2008 at 09:59 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •