Home >>Java Programs >Java Program to display the lower triangular matrix
In this example, we will create a java program to display the lower triangular matrix.
A lower triangular matrix is a square matrix in which all the elements above the principle diagonal will be zero.
<5>Program:5>
public class Main
{
public static void main(String[] args)
{
int rows, cols;
int a[][] = {
{1, 2, 3},
{8, 6, 4},
{4, 5, 6}
};
rows = a.length;
cols = a[0].length;
if(rows != cols){
System.out.println("Matrix should be a square matrix");
}
else {
System.out.println("Lower triangular matrix: ");
for(int i = 0; i < rows; i++){
for(int j = 0; j < cols; j++){
if(j > i)
System.out.print("0 ");
else
System.out.print(a[i][j] + " ");
}
System.out.println();
}
}
}
}