Java Program to Find maximum element of each row in a matrix Last Updated : 02 Dec, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report Given a matrix, the task is to find the maximum element of each row. Examples: Input : [1, 2, 3] [1, 4, 9] [76, 34, 21] Output : 3 9 76 Input : [1, 2, 3, 21] [12, 1, 65, 9] [1, 56, 34, 2] Output : 21 65 56 Approach : Approach is very simple. The idea is to run the loop for no_of_rows. Check each element inside the row and find for the maximum element. Finally, print the element. Below is the implementation : Java // Java program to find maximum // element of each row in a matrix public class GFG{ // Function to get max element public static void maxelement(int no_of_rows, int[][] arr) { int i = 0; // Initialize max to 0 at beginning // of finding max element of each row int max = 0; int[] result = new int[no_of_rows]; while (i < no_of_rows) { for (int j = 0; j < arr[i].length; j++) { if (arr[i][j] > max) { max = arr[i][j]; } } result[i] = max; max =0; i++; } printArray(result); } // Print array element private static void printArray(int[] result) { for (int i =0; i<result.length;i++) { System.out.println(result[i]); } } // Driver code public static void main(String[] args) { int[][] arr = new int[][] { {3, 4, 1, 8}, {1, 4, 9, 11}, {76, 34, 21, 1}, {2, 1, 4, 5} }; // Calling the function maxelement(4, arr); } } Output8 11 76 5 Time Complexity: O(R*C) where R and C are numbers of rows and columns of a given matrix respectively.Auxiliary Space: O(R), extra space for array result[] Please refer complete article on Find maximum element of each row in a matrix for more details! Comment More infoAdvertise with us Next Article Min and Max in a List in Java K kartik Follow Improve Article Tags : Java Practice Tags : Java Similar Reads Java Program for Maximum sum rectangle in a 2D matrix | DP-27 Write a Java program for a given 2D array, the task is to find the maximum sum subarray in it. For example, in the following 2D array, the maximum sum subarray is highlighted with blue rectangle and sum of this subarray is 29. This problem is mainly an extension of the Largest Sum Contiguous Subarra 5 min read Java Program for Maximum size square sub-matrix with all 1s Write a Java program for a given binary matrix, the task is to find out the maximum size square sub-matrix with all 1s. Recommended: Please solve it on "PRACTICE" first, before moving on to the solution.Approach: Let the given binary matrix be M[R][C]. The idea of the algorithm is to construct an au 5 min read How to find the Entry with largest Value in a Java Map Given a map in Java, the task is to find out the entry in this map with the highest value. Illustration: Input : Map = {ABC = 10, DEF = 30, XYZ = 20} Output : DEF = 30Input : Map = {1 = 40, 2 = 30, 3 = 60} Output : 3 = 60 Methods: There can be several approaches to achieve the goal that are listed 4 min read How to find the Entry with largest Key in a Java Map Given a map in Java, the task is to find out the entry in this map with the highest key. Examples: Input: Map = {ABC = 10, DEF = 30, XYZ = 20} Output: XYZ = 20 Input: Map = {1 = 40, 2 = 30, 3 = 60} Output: 3 = 60 Approach Iterate the map entry by entryfor (Map.Entry entry : map.entrySet()) { // Oper 2 min read Min and Max in a List in Java Given an unsorted list of integers, find maximum and minimum values in it. Input : list = [10, 4, 3, 2, 1, 20] Output : max = 20, min = 1 Input : list = [10, 400, 3, 2, 1, -1] Output : max = 400, min = -1Sorting This is least efficient approach but will get the work done. The idea is to sort the lis 5 min read How to read a Matrix from user in Java? Given task is to read a matrix from the user. The size and number of elements of matrices are to be read from the keyboard. Java // Java program to read a matrix from user import java.util.Scanner; public class MatrixFromUser { // Function to read matrix public static void readMatrixByUser() { int m 2 min read Like