Computer Science, asked by mohitsingh3852, 8 months ago

write a Java program for 3by 3 matrix and display it's right diagonal elements
and plzz it's a Java program not c++​

Answers

Answered by Anonymous
0

Answer:

Input: mat[][] =

{{ 2, 1, 7 },

{ 3, 7, 2 },

{ 5, 4, 9 }}

Output:

{ {0, 1, 0},

{3, 0, 2},

{0, 4, 0}}

Input: mat[][] =

{{1, 3, 5, 6, 7},

{3, 5, 3, 2, 1},

{1, 2, 3, 4, 5},

{7, 9, 2, 1, 6},

{9, 1, 5, 3, 2}}

Output:

{{0, 3, 5, 6, 0},

{3, 0, 3, 0, 1},

{1, 2, 0, 4, 5},

{7, 0, 2, 0, 6},

{0, 1, 5, 3, 0}}

Answered by Oreki
0

// A method to print the right diagonal of the passed int Array.

static void printRightDiagonal(int[ ][ ] array) {

for (int i = 0; i < array[0].length; i++)

System.out.print(array[i][array[0].length - 1 - i] + " ");

}

Similar questions