Java Program to Find maximum element of each row in a matrix Last Updated : 02 Dec, 2022 Comments Improve Suggest changes 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 Java Program to Find maximum element of each row in a matrix K kartik Follow Improve Article Tags : Java Searching Matrix Technical Scripter Java Programs DSA +2 More Practice Tags : JavaMatrixSearching Similar Reads Java Program to Find the Maximum Element in a Matrix Given a multi-dimensional 2D matrix of n rows and m column order N Ã M. The task is to find the maximum element in the given matrix. Illustration: Input : mat[][] = { {1,3,4,19}, {11,10,12,1}, {7,9,0,4,99} } Output : 99 Methods: Iterative method (naive approach)Using the principle of recursion (Bit 3 min read Java Program to Find k maximum elements of array in original order Given an array arr[] and an integer k, we need to print k maximum elements of given array. The elements should printed in the order of the input.Note : k is always less than or equal to n. Examples: Input : arr[] = {10 50 30 60 15} k = 2 Output : 50 60 The top 2 elements are printed as per their app 4 min read Java Program for Maximum and Minimum in a square matrix. Given a square matrix of order n*n, find the maximum and minimum from the matrix given. Examples: Input : arr[][] = {5, 4, 9, 2, 0, 6, 3, 1, 8}; Output : Maximum = 9, Minimum = 0 Input : arr[][] = {-5, 3, 2, 4}; Output : Maximum = 4, Minimum = -5 Naive Method : We find maximum and minimum of matrix 3 min read Java Program to Find Largest Element in an Array Finding the largest element in an array is a common programming task. There are multiple approaches to solve it. In this article, we will explore four practical approaches one by one to solve this in Java.Example Input/Output:Input: arr = { 1, 2, 3, 4, 5}Output: 5Input: arr = { 10, 3, 5, 7, 2, 12}Ou 4 min read Finding Maximum Element of Java Vector Vector implements a dynamic array that means it can grow or shrink as required. Like an array, it contains components that can be accessed using an integer index. We know two ways for declaring array i.e. either with a fixed size of array or size enter as per the demand of the user according to whic 3 min read Like