Part of one of our assignments was to generate an array and then find the sum, average, lowest, and highest values. I have all of those working, but our teacher has asked us instead to return the index of the highest and lowest values plus one (to coincide with a month number).
The issue I'm running into is that trying to return the index it always returns the highest value.
public double getHighRain()
{
double high = 0.0;
double highIndex = 0.0;
for(int index = 1; index < rainFall.length; index++)
{
if (rainFall[index] > high)
high = rainFall[index];
highIndex = index + 1;
}
//return high;
return highIndex;
}
/**
* Method uses enhanced for loop to calculate the lowest amount of rainfall
* @return
*/
public double getLowRain()
{
double low = rainFall[0];
double lowIndex = 0.0;
for(int index = 1; index < rainFall.length; index++)
{
if (rainFall[index] < low)
low = rainFall[index];
lowIndex = index + 1;
}
//return low;
return lowIndex;
}
getHighRain, why do you start at index1and skip the first element in that array?