Lower Triangular Matrix in Java

Lower triangular matrix in java program. A triangular matrix is a type of square matrix in the mathematical discipline of linear algebra. If all of the entries above the main diagonal are zero, a square matrix is called lower triangular. Similarly, if all of the entries below the major diagonal are zero, a square matrix is called upper triangular.

public class Main 
{
public static void main(String[] args)
{
int rows, cols;
int a[][] = {
{5, 2, 3},
{8, 6, 4},
{5, 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 is ");
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();
}
}
}
}

 

Output:

Lower triangular matrix is
5 0 0
8 6 0
5 5 6

Rows and Columns in Lower Triangular Matrix in Java

The first dimension of an image array in image processing is the column, and the second dimension is the row. The first dimension of an array (or matrix) is the row, and the second dimension is the column, according to standard linear algebra notation. By using this program we can implement in lower triangular matrix in java.

Lower Triangular Matrix in Java to Beginners in Matrix

A matrix is a set of numbers organised into a predetermined number of rows and columns.” These are usually real numbers. If you specify an integer array int arr[3][3], for example, the matrix will have three rows and three columns.

2D Array Lower Triangular Matrix in Java

2D arrays are stored as arrays of arrays in Java. As a result, the declaration of 2D arrays is similar to that of 1D array objects. 2D arrays are declared by using two sets of square brackets after defining a data type.

An array of arrays can be defined as a two-dimensional array. The matrices that make up the 2D array are represented as a collection of rows and columns. 2D arrays, on the other hand, are used to implement a data structure that resembles that of a relational database. We can execute the program to Lower Triangular Matrix in Java for beginners.

Similar Programs