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