# Upper Triangular Matrix in Java

Upper triangular matrix in Java program. A square matrix with all of the elements below the primary diagonal being zero is known as an upper triangular matrix. To find the upper triangular matrix, the matrix must be square, which means that the number of rows and columns must be equal.

`public class Main { public static void main(String[] args) { int rows, cols; int a[][] = { {3, 2, 3}, {5, 6, 4}, {7, 5, 6} }; rows = a.length; cols = a.length; if(rows != cols){ System.out.println("Matrix should be a square matrix"); } else { System.out.println("Upper triangular matrix is"); for(int i = 0; i < rows; i++){ for(int j = 0; j < cols; j++){ if(i > j) System.out.print("0 "); else System.out.print(a[i][j] + " "); } System.out.println(); } } } } `

Output:

Upper triangular matrix is
3 2 3
0 6 4
0 0 6

## Upper Triangular Matrix in Java for Beginners

Upper triangular matrix is a square matrix with elements sij = 0 for j i. In other words, if all of the entries below the main diagonal are zero, a square matrix is upper triangular. In other words, if all of the entries above the main diagonal are zero, a square matrix is lower triangular.

## What is Matrix in Maths

A matrix is a rectangular array of numbers that are arranged in rows and columns. The numbers are referred to as the matrix’s elements or entries. Engineering, physics, economics, and statistics, as well as various branches of mathematics, all use matrices. A matrix is a rectangular array of numbers or symbols organised in rows and columns. We have a 32 matrix in this example because the number of rows is equal to 3 and the number of columns is equal to 2. Using this program we can execute Upper Triangular Matrix in Java.

## How to Implement 3*3 Matrix in Java Program

Using the binary * operator and another loop, we can multiply two matrices in Java. A matrix can also be referred to as an array of arrays. Matrixes can be added, subtracted, and multiplied. When multiplying two matrices, one row element of the first matrix is multiplied by all columns of the second matrix. We can implement Upper Triangular Matrix in Java to execute matrix program.