Java Lab Assignment
Write a method named findMax. The method will take an array of doubles as an argument, and it will return the largest value in the array. (Note, you will have to create a new array of doubles) .
method must be well documented using JavaDoc, example:
/** * The find method checks if the target in the array
* @param String [] a - array of Strings
* @param String t - value to be searched for
* @return true if the String t is found, false otherwise
*/
public class FindMaxTest { /** * The findMax method finds and returns the maximum value in array * * @param arr - array of doubles * @return the largest value in the double array */ public static double findMax(double[] arr) { double max = arr[0]; for (int i = 0; i < arr.length; i++) { if (arr[i] > max) max = arr[i]; } return max; } public static void main(String[] args) { System.out.println(findMax(new double[] {4, 9, 1, 2, 6})); } }
Get Answers For Free
Most questions answered within 1 hours.