public class LowerTriangularMatrix {
public static void main(String[] args) {
int[][] matrix = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
printLowerTriangularMatrix(matrix);
}
public static void printLowerTriangularMatrix(int[][] matrix) {
int n = matrix.length;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= i; j++) {
System.out.print(matrix[i][j] + " ");
}
System.out.println();
}
}
}
1
4 5
7 8 9
matrix
represented as a two-dimensional array. We define a method printLowerTriangularMatrix
that takes the matrix as input and prints its lower triangular matrix to the console.