Multidimensional array--matrix

Gross matrix:X package afterfeb13; public class multidimarray { public static void main(String[] args) { int[][] mark = { { 10, 20, 80 }, { 40, 50, 60 }, { 70, 80, 90 } }; int total = 0; int sum = 0; for (int row = 0; row < mark.length; row++) { for (int col = 0; col < mark[row].length; col++) { if (row + col == 2) { total = total + mark[row][col]; } if (col == row) { sum = sum + mark[row][col]; } } }System.out.println("row + col == 2 = " + total); System.out.println("col==row = " + sum); System.out.println("sum+total = "+ (sum+total)); } } Output: row + col == 2 = 200 col==row = 150 sum+total = 350 maxium 1 present in which index: package afterfeb13; public class multidimentional { public static void main(String[] args) { int[][] arr = { { 1, 0, 1, 1, 1 }, { 1, 1, 1, 0, 0 }, { 1, 1, 1, 1, 0 } }; int max = 0; for (int row = 0; row < arr.length; row++) { int count = 0; for (int col = 0; col < arr[row].length; col++) { if (arr[row][col] == 1) { count++; } } System.out.println(row + "index count = " + count + " "); if (count > max) { max = count; } } System.out.println("max = " + max); } } Output: 0index count = 4 1index count = 3 2index count = 4 max = 4

Feb 28, 2025 - 12:04
 0
Multidimensional array--matrix

Gross matrix:X

package afterfeb13;

public class multidimarray {
    public static void main(String[] args) {
        int[][] mark = { { 10, 20, 80 }, { 40, 50, 60 }, { 70, 80, 90 } };
        int total = 0;
        int sum = 0;
        for (int row = 0; row < mark.length; row++) {
            for (int col = 0; col < mark[row].length; col++) {
                if (row + col == 2) {
                    total = total + mark[row][col];
                }
                if (col == row) {
                    sum = sum + mark[row][col];

                }
            }

        }System.out.println("row + col == 2 = " + total);
        System.out.println("col==row = " + sum);
        System.out.println("sum+total = "+ (sum+total));
    }

}

Output:

row + col == 2 = 200
col==row = 150
sum+total = 350

maxium 1 present in which index:

package afterfeb13;

public class multidimentional {
    public static void main(String[] args) {
        int[][] arr = { { 1, 0, 1, 1, 1 }, { 1, 1, 1, 0, 0 }, { 1, 1, 1, 1, 0 } };
        int max = 0;
        for (int row = 0; row < arr.length; row++) {
            int count = 0;
            for (int col = 0; col < arr[row].length; col++) {
                if (arr[row][col] == 1) {
                    count++;

                }
            }
            System.out.println(row + "index count = " + count + " ");
            if (count > max) {
                max = count;
            }
        }
        System.out.println("max = " + max);

    }

}

Output:

0index count = 4
1index count = 3
2index count = 4
max = 4