:Calculate the sum of all elements in given matrix.
44 85 20 33 -18
56 35 67 -2 -54 45
44 42 56 -76 90
-56 78 -14 79 11 33 in java
public class App{
public static void main(String []args){
int numbers[][]={{44,85,20,33,-18},{56,35,67,-2,-54,45},
{44,42,56,-76,90},{-56,78,-14,79,11,33}};
int sum=0;
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
System.out.print(numbers[i][j]+" ");
sum+= numbers[i][j];
}
System.out.println();
}
System.out.println("Sum = "+sum);
}
}
Comments
Leave a comment