// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
public class MatrixSummarize {
    public static boolean[][] summarize(boolean[][][] matrices) {
        assert matrices.length % 2 == 1 : "Number of matrices must be odd";
        int majority = (matrices.length + 1) / 2;
        boolean[][] result = new boolean[matrices[0].length][matrices[0][0].length];
        for(int i = 0; i < result.length; i++) {
            for(int j = 0; j < result[i].length; j++) {
                int ntrue = 0;
                for(int k = 0; k < matrices.length; k++) {
                    if(matrices[k][i][j]) ntrue++;
                    if(ntrue >= majority) {
                        result[i][j] = true;
                        break;
                    } else if(k + 1 - ntrue >= majority) {
                        break;
                    }
                }
            }
        }
        return result;
    }
    public static void print(boolean[][] result) {
        for(int i = 0; i < result.length; i++) {
            for(int j = 0; j < result[i].length; j++) {
                System.out.printf(" %-5b", result[i][j]);
            }
            System.out.println();
        }   
    }
    public static void main(String[] args){
        boolean [][] matrix1 = {
            { true, true, false },
            { true, false, true },
            {false, true, false }
         };
        boolean [][] matrix2 = {
            { false, true, false },
            { true, false, false },
            { false, true, false }
         };
        boolean [][] matrix3 = {
            { true, false, true },
            { true, false, false },
            { false, true, false }
        };
        boolean[][][] matrices = { matrix1, matrix2, matrix3 };
        boolean[][] result = summarize(matrices);
        print(result);
    }
}
