• 12-09-2008, 11:31 AM
osborne
This is the Output i want to work out using multidimensional array?
This is the output...
the sum to the 1st row and sum of the 2nd column...

1 2 3 = 6
4 5 6 = 15
7 8 9 = 24
121518

• 12-09-2008, 12:16 PM
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
osborne
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
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
Sven
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();         }     } }```
Please use code tags for formatting.