public static double sum(double[] data){
  double sum=0.0;
  for (int i=0; i < data.length; i++) {
    if (Double.isNaN(data[i]))     continue;
    sum+=data[i];
  }
  return sum;
}

public static double sum ( double [ ] data ) { double sum = 0.0 ; for ( int i = 0 ; i < data . length ; i ++ ) { if ( Double . isNaN ( data [ i ] ) ) continue ; sum += data [ i ] ; } return sum ; }
build the sum of all elements in the array , ignoring elements that are nan .
