public static int rowMaxElem(double[][] a, int k) {
        int max = k;
        for (int i = k + 1; i < a.length; i++) {
            if (Math.abs(a[i][k]) > Math.abs(a[max][k]))
                max = i;
        }
        if (a[max][k] == 0)
            return -1;
        return max;
    }