Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.* ;
- class ColumnSums
- {
- public static void main ( String[] args ) throws IOException
- {
- int[][] data = { {3, 2, 5},
- {1, 4, 4, 8, 13},
- {9, 1, 0, 2},
- {0, 2, 6, 3, -1, -8} };
- // declare the sum
- int sum;
- // compute the sums for each row
- for ( int col=0; col < 6; col++)
- {
- sum = 0;
- // compute the sum for this row
- for ( int row=0; row < data.length; row++)
- {
- if (data[row].length > col)
- sum = data[row][col] + sum;
- }
- // write the sum for this row
- System.out.println("Columm " + col + " = " + sum);
- }
- System.out.println();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement