Results 1 to 5 of 5

- 12-09-2008, 11:31 AM #1Member
- Join Date
- Dec 2008
- Posts
- 2

- Rep Power
- 0

- 12-09-2008, 12:16 PM #2Senior Member
- Join Date
- Jun 2008
- Posts
- 2,571

- Rep Power
- 10

An array of sums and two nested loops.

Give it a try, and then post the problematic code and give a complete description of your actual problem.

- 12-09-2008, 01:25 PM #3Member
- Join Date
- Dec 2008
- Posts
- 2

- Rep Power
- 0

## this are the code im working....

public class Main {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

int[][] matrix = new int[4][3];

int row, col, value = 1;

final int NUM_ROWS = matrix.length;

final int NUM_COLS = matrix[0].length;

for (row = 0; row < NUM_ROWS; row++) {

for (col = 0; col < NUM_COLS; col++) {

matrix[row][col] = value;

value++;

}

}

for (row = 0; row < NUM_ROWS; row++) {

for (col = 0; col < NUM_COLS; col++) {

System.out.print(matrix[row][col] + "\t");

}

System.out.println();

}

}

}

I need help with my code that will find the sum of the 3 rows which equal 6, 15, 24, 33 then add the columns that equal 22, 26 , 30.

here is my code so far:

- 12-09-2008, 01:32 PM #4Senior Member
- Join Date
- Jun 2008
- Posts
- 2,571

- Rep Power
- 10

Well, like I said, create a single dimensional array for the sums (that will correlate, of course, to the second dimension in your 2 dimensional array). Then, using nested loops, sum the values from the second dimension columns using the same index into the sum array.

At least*try*it.

- 12-09-2008, 05:30 PM #5Member
- Join Date
- Dec 2008
- Location
- Enschede, Overijssel, the Netherlands
- Posts
- 19

- Rep Power
- 0

Java Code:public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { int[][] matrix = new int[4][3]; int row, col, value = 1; final int NUM_ROWS = matrix.length; final int NUM_COLS = matrix[0].length; for (row = 0; row < NUM_ROWS; row++) { for (col = 0; col < NUM_COLS; col++) { matrix[row][col] = value; value++; } } for (row = 0; row < NUM_ROWS; row++) { for (col = 0; col < NUM_COLS; col++) { System.out.print(matrix[row][col] + "\t"); } System.out.println(); } } }

## Bookmarks