
columan wise total matrix?

Java sum of individual columns of matrix
The given code determines the sum of individual column of matrix and display them.
import java.util.*;
class FindSumMatrix{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int[][] A = new int[3][3];
System.out.println("Enter elements for matrix A : ");
for (int i=0 ; i < A.length ; i++){
for (int j=0 ; j < A[i].length ; j++){
A[i][j] = input.nextInt();
}
}
int c1=0,c2=0,c3=0;
System.out.println("Matrix A: ");
for (int i=0 ; i < A.length ; i++){
System.out.println();
for(int j=0 ; j < A[i].length ; j++){
System.out.print(A[i][j]+" ");
}
}
for (int i=0 ; i < A.length ; i++){
c1+=A[i][0];
c2+=A[i][1];
c3+=A[i][2];
}
System.out.println();
System.out.println();
System.out.println("Col1: "+c1);
System.out.println("Col2: "+c2);
System.out.println("Col3: "+c3);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.