Here you can find the source of sum(int[][][] X, int[] coords)
private static int sum(int[][][] X, int[] coords)
//package com.java2s; //License from project: Open Source License public class Main { private static int sum(int[][][] X, int[] coords) { int x = coords[0]; int y = coords[1]; int z = coords[2]; int xlow = x == -1 ? 0 : x; int xhigh = x == -1 ? X.length - 1 : x; int ylow = y == -1 ? 0 : y; int yhigh = y == -1 ? X[0].length - 1 : y; int zlow = z == -1 ? 0 : z; int zhigh = z == -1 ? X[0][0].length - 1 : z; int sum = 0; int count = 0; for (int i = xlow; i <= xhigh; i++) { for (int j = ylow; j <= yhigh; j++) { for (int m = zlow; m <= zhigh; m++) { int c = X[i][j][m]; if (c >= 0) { sum += c;/* w w w .j av a 2s . c o m*/ count++; } } } } return count == 0 ? -1 : sum; } }