0
Write a method to find the sum of all the elements of a particular column in the integer matrix
Write a method to find the sum of all the elements of a particular column in the integer matrix
1 Respuesta
+ 1
try this
public class array01 {
public static int sumColumn (int[] [] matrix, int column) {
int sum=0;
for (int i=0; i<matrix.length;i++){
sum=sum+matrix[i][column];
}
return sum;
}
public static void main(String[] args) {
int matrixa[][] ={{1,2,3,4},{2,6,8,9},{8,6,9,8}};
System.out.println(sumColumn(matrixa,1));
}
}