Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SummingColumn8_1 {
- public static void main(String[] args) {
- // create a matrix
- int[][] matrix={
- {1,2,3},
- {4,5,6},
- };
- // outer loop controls the column number
- // inner loop advances present column to the next row
- for (int j=0; j<matrix[0].length; j++){
- int columnTotal=0;
- for (int i=0; i<matrix.length; i++){
- columnTotal+= matrix[i][j];
- }
- System.out.println("The total for column "+j+ " is "+ columnTotal);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement