You don't need to put that much work into the least and most methods. Instead, sort the arrays and pull from the first and last:
PHP Code:
public static double mostRain(double[] array)
{
double[] copy = array.clone();
Arrays.sort(copy);
return copy[copy.length - 1];
}
public static double leastRain(double[] array)
{
double[] copy = array.clone();
Arrays.sort(copy);
return copy[0];
}
To get the month index for the most and least would be similar to what you have, but you don't take the values of.
PHP Code:
public static int mostRainMonth(double[] array)
{
int iMonth = 0;
for (int i = 1; i < array.length; ++i)
{
if (array[i] > array[iMonth])
{
iMonth = i;
}
}
return iMonth;
}
public static int leastRainMonth(double[] array)
{
int iMonth = 0;
for (int i = 1; i < array.length; ++i)
{
if (array[i] < array[iMonth])
{
iMonth = i;
}
}
return iMonth;
}
Conflicting months where two match cannot be reported this way.
The hang is an infinite loop here:
for (int i=0; i < 12; i = i++). Remove the assignment (or just use what I posted since I don't use a loop in that counter).
I'd give the averageRain an overload as well:
PHP Code:
public static double averageRain(double[] array)
{
return averageRain(array, totalRain(array));
}
Also, in the future please choose a better topic title to describe the problem, and use [php][/php] or [code][/code] tags around code to preserve the formatting.