CS 1713 Introduction to Computer Science Daily Problem

Write a method that takes an array of doubles as a parameter and returns the largest value stored in the array. If the array has no elements, return Double.MIN_VALUE.

Solution:


public double findLargest(double[] array) {
   double max;
   if (array.length == 0)
      return Double.MIN_VALUE;
   max = array[0];
   for (int k=1;k<array.length;k++)
      if (max < array[k])
         max = array[k];
   return max;
}