Java Program to Find Maximum And Minimum Number in a Matrix

In this post we’ll see a Java program to find maximum and minimum number in a matrix.

Java program

Logic for finding the maximum and minimum number in a matrix goes as follows-

Initially assign the element at the index (0, 0) of the matrix to both min and max variables. Then iterate the matrix one row at a time and compare each element with the max variable first, if max variable is less than the current element then assign the current element to the max element else compare current element with the min variable, if min variable is greater than the current element then assign the current element to the min element.

Output

That’s all for the topic Java Program to Find Maximum And Minimum Number in a Matrix. If something is missing or you have something to share about the topic please write a comment.


You may also like

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.