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 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 Java Program to Get the Maximum Element From a Vector Prerequisite: Vectors in Java Why We Use Vector? Till now, we have learned two ways for declaring either with a fixed size of array or size enter as per the demand of the user according to which array is allocated in memory. int Array_name[Fixed_size] ; int array_name[variable_size] ; Both ways we l 4 min read Finding Maximum Element of Java ArrayList For finding the maximum element in the ArrayList, complete traversal of the ArrayList is required. There is an inbuilt function in the ArrayList class to find the maximum element in the ArrayList, i.e. Time Complexity is O(N), where N is the size of ArrayList, Let's discuss both the methods. Example 2 min read Java Program to Find median in row wise sorted matrix We are given a row-wise sorted matrix of size r*c, we need to find the median of the matrix given. It is assumed that r*c is always odd.Examples:Â Input : 1 3 5 2 6 9 3 6 9 Output : Median is 5 If we put all the values in a sorted array A[] = 1 2 3 3 5 6 6 9 9) Input: 1 3 4 2 5 6 7 8 9 Output: Media 4 min read Java Program to Maximize sum of diagonal of a matrix by rotating all rows or all columns Given a square matrix, mat[][] of dimensions N * N, the task is find the maximum sum of diagonal elements possible from the given matrix by rotating either all the rows or all the columns of the matrix by a positive integer. Examples: Input: mat[][] = { { 1, 1, 2 }, { 2, 1, 2 }, { 1, 2, 2 } }Output: 3 min read Java Program to Return the Largest Element in a List Given a List, find the largest element in it. There are multiple approaches to tackle this problem, such as iterating through the List or using various inbuilt functions. Input : List = [5, 3, 234, 114, 154] Output : 234 Input : List = {10, 20, 4} Output : 20Approach 1: Using a ForEach Loop Create L 3 min read Like