Hello again. I been trying to do this java HW all day but i am starting to get a headache lol. This HW has to do with getting the user to input 6 numbers and save them into an array. After that is to invoke the min method to return the index of the smallest element and display the min value within. Then to invoke the moveMin method to shift the elements after the smallest element, one position to the left and fill the last element with the smallest element. Most of the code was given to us from our professor and told us we don't have to change anything in the main method, but to add code in the last 2 methods which were left blank for us.....this is the given code :
public class Lab2 {
// Main method
public static void main(String[] args) {
double[] numbers = new double[6];
int index;
java.util.Scanner input = new java.util.Scanner(System.in);
System.out.println("Enter six different double numbers: ");
for (int i = 0; i < numbers.length; i++)
numbers[i] = input.nextDouble();
index = min(numbers);
System.out.println("The min is " + numbers[index]);
moveMin(numbers, index);
System.out.println("The re-ordered Array is: ");
for (int i = 0; i < numbers.length; i++)
System.out.print(numbers[i] + ", ");
}
public static int min(double[] list) {
}
public static void moveMin(double[] list, int position) {
}
}
----------------------------------------------------------------------------------------------------------------------------------
and this is what i have typed so far in the last 2 methods but i don't know if its even right :
public static int min(double[] list) {
double min = 0;
for (index = 1; index < numbers.length; i++){
if (numbers[min] > numbers[index])
min = index;
}
public static void moveMin(double[] list, int position) {
double temp = min[index];
My professors input was 2, 3, 4, 1, 5, 6. And it printed out min as 1.0, and the re-ordered array is : 2.0, 3.0, 4.0, 5.0, 6.0, and 1.0.
Again from my last thread, I am still kind of new to java. Last java class i took was a yr ago (had to take time off from school) so i forgot quit a bit
Thanks in advanced.