1. Member Join Date
Dec 2008
Posts
2
Rep Power
0

## Please Help me w/ this Problem...

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  Reply With Quote

2. Senior Member Join Date
Jun 2008
Posts
2,568
Rep Power
14

## 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.  Reply With Quote

3. Member 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;
int row, col, value = 1;
final int NUM_ROWS = matrix.length;
final int NUM_COLS = matrix.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:  Reply With Quote

4. Senior Member Join Date
Jun 2008
Posts
2,568
Rep Power
14

## 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.  Reply With Quote

5. Member 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;
int row, col, value = 1;
final int NUM_ROWS = matrix.length;
final int NUM_COLS = matrix.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.  Reply With Quote

#### Posting Permissions

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