Answers for "maximum value in an array"

C++
2

Find the maximum number of an array js

var arr = [1, 2, 3];
var max = arr.reduce(function(a, b) {
  return Math.max(a, b);
});
Posted by: Guest on October-22-2020
1

Find Maximum array

Array -- Find Maximum
Write a method that can find the maximum number from an int Array
Solution 1:
public static void main(String[] args) {
    int[] arr = new int[]{2,4,6,8,20};
    System.out.println(maxValue(arr));

public static int maxValue( int[]  n ) {
int max = Integer.MIN_VALUE;
for(int each: n)
if(each > max)
max = each;
 
return max;
}
 
Solution 2:
public static int maxValue( int[]  n ) {
Arrays.sort( n );
return  n [ n.lenth-1 ];
}
Posted by: Guest on September-29-2021
1

Find the maximum number of an array js

function getMaxOfArray(numArray) {
    return Math.max.apply(null, numArray);
}
Posted by: Guest on October-22-2020
2

max element in array

int max;
max=INT_MIN;

for(int i=0;i<ar.length();i++){
	if(ar[i]>max){
    	max=ar[i];
    }
Posted by: Guest on October-09-2020

Code answers related to "maximum value in an array"

Browse Popular Code Answers by Language