Print matrix in Z form.
Input: mat[][] = {1, 2, 3,
4, 5, 6,
7, 8, 9}
Output: 1 2 3 5 7 8 9
public class PrintTheMatrixOrder { public static void printTheMatrix(int mat[][]) { for (int i = 0; i < mat.length; i++) { System.out.print(mat[0][i] + " "); } int n = mat.length - 2; for (int i = 1; i < mat.length - 1; i++) { System.out.print(mat[i][n] + " "); n--; } for (int i = 0; i < mat.length; i++) { System.out.print(mat[mat.length - 1][i] + " "); } } public static void main(String[] args) { int mat[][] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; printTheMatrix(mat); } }
Thanks and Regards,
Solution provided by Nilmani Prashanth
I need training from you ,from scratch onwards