I am looking for some help on my programming.I need to find sum of each column in 2d array. The result suppose to be like this.: {817.192, 471,1821, 144.7155, 115.6173}
Here is my code please take look.
import java.io.*;
public class Columnsun {
public static void main(String[] args) {
double[][] initialArray = { { 7.432, 8.541, 23.398, 3.981 },
{ 721.859, 6.9211, 29.7505, 53.6483 },
{ 87.901, 455.72, 91.567, 57.988 } };
}
public void columnSum(double[][] initialArray) {
double sum = 0;
for (int column = 0; column < initialArray.length-1; column++) {
sum = 0;
for (int row = 0; row < initialArray.length; row++)
sum = initialArray[row].length;
// the sum of each row.
// for(int row = 0; row <= initialArray.length ; row++){
// sum = 0;
// for(int col = 0; col<initialArray[(int) row].length; col++){
// sum += initialArray[ row][ col];
}
// System.out.println("The sum of row" + row +"is"+sum);
System.out.print(sum + "\t");
return;
}
}
I don't have any compile error, but there is nothing print out.
I don't have any compile error, but there is nothing print out.

New Topic/Question
Reply



MultiQuote






|