Answers for "Find Minimum array"

0

javascript get minimum value in array

// Getting min value
var arr = [5,1,9,5,7];
var min = Math.min(...arr);
console.log(min); // 1

// Getting max value
var arr = [5,1,9,5,7];
var min = Math.max(...arr);
console.log(min); // 9
Posted by: Guest on January-13-2021
0

Find Minimum array

Array -- Find Minimum
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 min = Integer.MAX_VALUE;
for(int each: n)
if(each < min)
min = each;
 
return min;
}
 
Solution 2:
public static int maxValue( int[]  n ) {
Arrays.sort( n );
return  n [ 0 ];
}
Posted by: Guest on September-29-2021

Code answers related to "Find Minimum array"

Browse Popular Code Answers by Language