Java Program to Display Lower Triangular Matrix Last Updated : 23 Apr, 2023 Comments Improve Suggest changes Like Article Like Report Lower Triangular Matrix is a square matrix in which all the elements above the principal diagonal are 0. If the matrix is not a square matrix, it can never be called the lower triangular matrix. Examples Input 1: mat[][] = { {2, 1, 4}, {1, 2, 3}, {3, 6, 2}} Output : mat[][]= {{2, 0, 0}, {1, 2, 0}, {3, 6, 2}} Explanation : All the element below the principal diagonal needs to be 0. Input 2 : mat[][]= {{4, 6}, {2, 8}} Output : mat[][]= {{4, 0}, {2, 8}} Input 3 : mat[][] = { {2, 1, 4, 6}, {1, 2, 3, 7}, {3, 6, 2, 8} } Output : Matrix should be a Square Matrix Approach: If the matrix has equal rows and columns, continue the program else exit the program.Run the loop over the whole matrix, and for the rows, whose column number is greater than row number, make the element at that position equal to 0. Below is the implementation of the above approach: Java // Java program for displaying lower triangular matrix import java.io.*; class GFG { static void lowerTriangularMatrix(int matrix[][]) { int row = matrix.length; int col = matrix[0].length; // if number of rows and columns are not equal, // then return back if (row != col) { System.out.println( "Matrix should be a Square Matrix"); return; } else { // looping over the whole matrix for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { // for the rows,whose column number is // greater then row number,mark the // element as 0 if (i < j) { matrix[i][j] = 0; } } } System.out.println( "Lower Triangular Matrix is given by :-"); // printing the lower triangular matrix for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { System.out.print(matrix[i][j] + " "); } System.out.println(); } } } public static void main(String[] args) { // driver code int mat[][] = { { 2, 1, 4 }, { 1, 2, 3 }, { 3, 6, 2 } }; // calling the function lowerTriangularMatrix(mat); } } Output: Lower Triangular Matrix is given by :- 2 0 0 1 2 0 3 6 2 Space Complexity: Matrix can be changed in-place. i.e no extra matrix space required. 0(N^2)Time Complexity: 0(N^2) Comment More infoAdvertise with us Next Article Java Program to Display Lower Triangular Matrix L lavishgarg26 Follow Improve Article Tags : Java Matrix Java Programs DSA Practice Tags : JavaMatrix Similar Reads Java Program to Display Upper Triangular Matrix Upper Triangular Matrix is a matrix in which all the elements below the principal matrix are 0. A necessary condition is that matrix must be Square matrix in nature. If the matrix is not a square matrix, it can never be called the upper triangular matrix. ExamplesInput 1: mat[][] = { {2, 1, 4}, {1, 2 min read Java Program to check if matrix is lower triangular Given a square matrix and the task is to check the matrix is in lower triangular form or not. A square matrix is called lower triangular if all the entries above the main diagonal are zero. Examples: Input : mat[4][4] = {{1, 0, 0, 0}, {1, 4, 0, 0}, {4, 6, 2, 0}, {0, 4, 7, 6}}; Output : Matrix is in 2 min read Java Program to check if matrix is upper triangular Given a square matrix and the task is to check the matrix is in upper triangular form or not. A square matrix is called upper triangular if all the entries below the main diagonal are zero. Examples: Input : mat[4][4] = {{1, 3, 5, 3}, {0, 4, 6, 2}, {0, 0, 2, 5}, {0, 0, 0, 6}}; Output : Matrix is in 2 min read Java Program to Display Floydâs Triangle Floydâs triangle is a triangle with first natural numbers. It is the right arrangement of the numbers/values or patterns. Basically, it is a left to right arrangement of natural numbers in a right-angled triangle Illustration: Suppose if no of rows to be displayed is 5 then the desired output should 2 min read Java Program to Print Mirror Lower Star Triangle Pattern In this article, we are going to learn how to print mirror lower star triangle patterns in Java. Illustration: Input: number = 7 Output: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Methods: We can print mirror lower star triangle pa 5 min read Java Program to Check Whether a Given Matrix is Lower Triangular Matrix or Not In the lower triangular matrix, the elements that are present above the diagonal should be 0. Given a matrix and the task is to check the matrix is in lower triangular form or not. A matrix must be a square matrix. A square matrix is called lower triangular if all the entries above the main diagonal 2 min read Java Program to Print Downward Triangle Star Pattern Downward triangle star pattern means we want to print a triangle that is downward facing means base is upwards and by default, orientation is leftwards so the desired triangle to be printed should look like * * * * * * * * * * Example Java // Java Program to Print Lower Star Triangle Pattern // Main 2 min read Java Program to Print Left Triangle Star Pattern In this article, we will learn about printing Left Triangle Star Pattern. Examples: Input : n = 5 Output: * * * * * * * * * * * * * * * Left Triangle Star Pattern: Java import java.io.*; // java program for left triangle public class GFG { // Function to demonstrate printing pattern public static vo 5 min read Java Program to Print Pascal's Triangle Pascal's triangle is a pattern of the triangle which is based on nCr.below is the pictorial representation of Pascal's triangle.Example:Input : N = 5Output: 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1Approach #1: nCr formula: n ! / ( n - r ) ! r ! After using nCr formula, the pictorial representation becomes: 0C0 3 min read Java Program to Add two Matrices Given two matrices A and B of the same size, the task is to add them in Java. Examples: Input: A[][] = {{1, 2}, {3, 4}} B[][] = {{1, 1}, {1, 1}} Output: {{2, 3}, {4, 5}} Input: A[][] = {{2, 4}, {3, 4}} B[][] = {{1, 2}, {1, 3}} Output: {{3, 6}, {4, 7}}Program to Add Two Matrices in JavaFollow the Ste 2 min read Like