DEV Community

Neelakandan R
Neelakandan R

Posted on β€’ Edited on

7 3 3 3 3

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));
    }

}

Enter fullscreen mode Exit fullscreen mode

Output:

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

maxium 1 present in which index:

public class multidimentional {
    public static void main(String[] args) {
        int[][] arr = { { 1, 1, 1, 1, 0 }, { 1, 1, 1, 0, 0 }, { 0, 1, 0, 1, 0 } };
        int max = 0;
        int row_MaxOne = 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;
                row_MaxOne = row;// sending row index[0][1][2]
            }
        }
        System.out.println("index has max ones = " + row_MaxOne + "th index");
        System.out.println("max one present is = " + max);

    }

}


Enter fullscreen mode Exit fullscreen mode

Output:

index has max ones = 0th index
max one present is = 4

AWS Q Developer image

Your AI Code Assistant

Ask anything about your entire project, code and get answers and even architecture diagrams. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Start free in your IDE

Top comments (0)

AWS Q Developer image

Your AI Code Assistant

Ask anything about your entire project, code and get answers and even architecture diagrams. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Start free in your IDE

πŸ‘‹ Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay