Horje
how to find the largest number in a 2d array java Code Example
how to find the largest number in a 2d array java
// Assume the 2D array is holding int values
// Method for finding largest number in array given below
// if 2D array is null or empty, return min int value

public int findLargest(int[][] mat) {
	int max = Integer.MIN_VALUE; // running max value
  	if(mat == null || mat.length == 0) {
     	return max; // return min int if mat is null or empty 
    }
  
  	final int ROW = mat.length; // nb of rows in 2D array
  	final int COL = mat[0].length; // nb of cols in 2D array
  	// Iterate over elements to find largest value
  	for(int row=0; row < ROW; row++) {
    	for(int col=0; col < COL; col++) {
        	if(mat[row][col] > max) {
            	max = mat[row][col]; // update running max if larger val is found 
            }
        }
    }
	
  	return max;
}




Java

Related
clsoe keyboard android studio Code Example clsoe keyboard android studio Code Example
android hide system bar programmatically Code Example android hide system bar programmatically Code Example
joptionpane hello world Code Example joptionpane hello world Code Example
java botton code Code Example java botton code Code Example
leetcode 416 Code Example leetcode 416 Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8