"HELLO WORLD"
This is my first post on the site and am I in week 5 of a programming java course. I should mention that I am a bit of a beginner still. My assignment this week is as follows:
"Create an (double) array to store the scores below. Then create a sorting class using one of the above methods. Make sure the sorting class processes double arrays (double[] arrayName;). Create a client class to call the sorting Class. Pass the array of scores to the Sorting class. Sort the array from smallest to largest and printout the sorted array."
The work I have done so far is created the first class for gathering and printing the results and it is error free. I have also created the second class but I have an error I can't figure out. I have titled this post the error I am receiving. By the way, I am working with NetBeans (not my favorite program). Anyhow, here is the code for my second class:
public class SortingClass {
public static void SortingClass ( double[] array )
{
double[] array1 = new double[]
{53.5, 60.3, 96.2, 53.3, 56.4, 52.7, 76.4, 77.5, 71.0, 78.2,
65.2, 59.3, 80.5, 92.1, 85.7, 78.7, 66.2, 88.8, 50.2, 73.4};
double temp;
int max;
for (int i = 0; i < array1.length - 1; i ++)
{
max = indexOfLargestElement ( array1, array1.length - i );
temp = array1[max];
array1[max] = array1[array1.length - i - 1];
array1[array1.length - i - 1] = temp;
}
}
public static double indexOfLargestElement ( double[] array1, int size)
{
int index = 0;
for ( int i = 1; i < size; i++ )
{
if ( array1[i] > array1[index] )
index = i;
}
return index;
}
}
The error I am receiving is at the line:
max = indexOfLargestElement ( array1, array1.length - i );
The error message to recap is "Incompatible type: possible lossy conversion from double to int."