In: Computer Science
Write a program that uses an array of doubles initialized to whatever values you wish. Write methods to calculate and return the minimum and a method to calculate and return the maximum value in the array. You must write YOUR ORIGINAL methods for minimum and maximum. You MAY NOT use Math class methods or other library methods.
Write an additional method that accepts the array as a parameter and then creates and returns a new array with all the same values as the original plus 10. (num +=10)
public class MinMaxArrayDoubles { static double minArray(double arr[]){ double res = arr[0]; for(int i = 1;i<arr.length;i++){ if(res > arr[i]){ res = arr[i]; } } return res; } static double maxArray(double arr[]){ double res = arr[0]; for(int i = 1;i<arr.length;i++){ if(res < arr[i]){ res = arr[i]; } } return res; } static double[] createArray(double arr[]){ double res[] = new double[arr.length]; for(int i = 0;i<arr.length;i++){ res[i] = arr[i]+10; } return res; } public static void main(String[] args) { double[] arr = {3.4,5.6,8.7,1.3,2.5,4.788}; System.out.println("Minimum = "+minArray(arr)); System.out.println("Maximum = "+maxArray(arr)); double[] res = createArray(arr); for(int i = 0;i<res.length;i++){ System.out.print(res[i]+" "); } System.out.println(); } }