Question
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
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)
So far I have:
public static void main (String[] args) { Scanner scan = new Scanner (System.in); //making an array double myArray[]; myArray = new double[5]; System.out.println ("Enter numbers:"); //putting in a numbers in an array for (int a = 0; a < 5; a++) { myArray[a] = scan.nextDouble(); } //print the array for (int a = 0; a < 5; a++) { System.out.print (myArray[a] + " "); } System.out.println(); System.out.println ("The Min value in the array is: " + findtheMinimum(myArray)); System.out.println(); System.out.println ("The Max value in the array is: " + findTheMaximum(myArray)); System.out.println(); System.out.println ("This is the new array: " + addTen(myArray)); } //Find the minimum number public static double findtheMinimum (double[] myArray) { double min = myArray[0]; for (int a = 1; a < 5;a++) { if( myArray[a] < min) { min = myArray[a]; } } return min; } //Find the maximum number public static double findTheMaximum (double[] myArray) { double max = myArray[0]; for (int a = 1; a < 5;a++) { if( myArray[a] > max) { max = myArray[a]; } } return max; } public static double addTen (double[] myArray) { double myArray2[]; myArray2 = new double[5]; for (int a = 0; a < 5; a++) { myArray2[a] = myArray[a]; } return myArray; } }
The add ten portion won't work. Please help.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started