0

I am trying to write a method that will return the month with the lowest rainfall amount. The problem is that I have to initialize my variable but then my method always returns a "0". How can I fix this problem?

Here is my code:

public int getLowestRainFallMonth()
    {
        double lowest = rainAmount[0];
        int lowMonth = 0;
        for (int index = 1; index < ARRAY_SIZE; index++)
        {
            if (rainAmount[index] < lowest)
            {
                lowest = rainAmount[index];
                lowMonth = index;
            }
        }
        return lowMonth;

Edited by Nick Evan: Fixed formatting

1
Contributor
1
Reply
3
Views
7 Years
Discussion Span
Last Post by gherudek
0

OK. I think I figured it out. Not sure if it's the best way to do it but at least it works.

public int getLowestRainFallMonth()
    {
    double lowest = rainAmount[0];
    int lowMonth = (int) rainAmount[0];
    for (int index = 1; index < ARRAY_SIZE; index++)
    {
          if (rainAmount[index] < lowest)
        {
        lowest = rainAmount[index];
        lowMonth = index;
        }
    }
    return lowMonth;

Edited by Nick Evan: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.