Write a method to find the sum of all the elements of a particular column in the integer matrix | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

17th Nov 2016, 12:42 PM
沫雅公子
1 Answer
+ 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)); } }
17th Nov 2016, 1:39 PM
Simone Novaro
Simone Novaro - avatar