Java Program to display the upper triangular matrix17 Mar 2025 | 2 min read In this program, we need to display the upper triangular matrix. Upper Triangular MatrixUpper triangular matrix is a square matrix in which all the elements below the principle diagonal are zero. To find the upper triangular matrix, a matrix needs to be a square matrix that is, the number of rows and columns in the matrix need to be equal. Dimensions of a typical square matrix can be represented by n x n. ![]() Consider the above example, principle diagonal element of given matrix is (1, 6, 6). All the elements below diagonal needs to be zero to convert it into an upper triangular matrix, in our example, those elements are at positions (2, 1), (3, 1) and (3, 2). To convert given matrix into the upper triangular matrix, loop through the matrix and set the values of the element to zero where row number is greater than column number. Algorithm
programOutput: Upper triangular matrix: 1 2 3 0 6 4 0 0 0 Next TopicJava Programs |
An array numArr[] is given, which only contains the non-negative integers, and an integer sp is also provided. The task is to partition the array into sp continuous subarrays such that the largest sum among these sp subarrays is minimum. Note that subarrays can never be...
19 min read
In this program, we need to calculate the sum of elements in each row and each column of the given matrix. Above diagram shows the sum of elements of each row and each column of a matrix. Algorithm STEP 1: START STEP 2: DEFINE rows, cols, sumRow, sumCol STEP 3:...
3 min read
Java String to float We can convert String to float in java using Float.parseFloat() method. Scenario It is generally used if we have to perform mathematical operations on the string that contains float number. Whenever we get data from textfield or textarea, entered data is received as a string....
1 min read
Multiplication of matrix is a core concept in programming. We can perform matrix multiplication in Java using a simple nested for loop approach to advance approach. The nested for loop approach has a time complexity of O(n3). The time complexity of matrix multiplication can be improved...
17 min read
Java Convert Binary to Decimal We can convert binary to decimal in java using Integer.parseInt() method or custom logic. Java Binary to Decimal conversion: Integer.parseInt() The Integer.parseInt() method converts string to int with given redix. The signature of parseInt() method is given below: public static int parseInt(String s,int redix) Let's see...
2 min read
It is a very interesting problem frequently asked in interviews of top IT companies like Google, Amazon, TCS, Accenture, Adobe, Apple, Infosys, etc. By solving the problem, one wants to check the logical ability, critical thinking, and problem-solving skill of the interviewee. So, in this section,...
5 min read
Java Program to print Odd and Even Numbers from an Array We can print odd and even numbers from an array in java by getting remainder of each element and checking if it is divided by 2 or not. If it is divided by 2, it is...
1 min read
Program to print the elements of an array present on even position In this program, we need to print the element which is present on even position. Even positioned element can be found by traversing the array and incrementing the value of i by 2. In the...
1 min read
Selection sort is an easy-to-understand and straightforward kind of algorithm that sorts elements in a list or array, either ascending or descending. The element idea at the core of selection sort is to obtain repeatedly the minimum (or the maximum) element of the unsorted part...
7 min read
In this program, we will create a circular linked list and insert every new node at the beginning of the list. If the list is empty, then head and tail will point to the newly added node. If the list is not empty, then we...
6 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India