Answers for "find max and min value in array functions java"

3

max in array java

// Initializing array of integers 
        Integer[] num = { 2, 4, 7, 5, 9 }; 
// using Collections.min() to find minimum element 
        // using only 1 line. 
        int min = Collections.min(Arrays.asList(num)); 
  
        // using Collections.max() to find maximum element 
        // using only 1 line. 
        int max = Collections.max(Arrays.asList(num));
Posted by: Guest on September-24-2020
1

java max array

public static double max(double[] arr) {
  double result = arr[0];
  for (int i = 1; i < arr.length; ++i) {
    if (result < arr[i]) result = arr[i];
  }
  return result;
}
Posted by: Guest on February-05-2021

Code answers related to "find max and min value in array functions java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language