Harry Peters wrote:Lines 51-64 are where I would need help. If I try and compile, Java's warning is: "variable min is already defined in method howManyHaveThisPopulation(int,int)". So I know this is wrong:
You are not allowed to declare two local variables (in a method) with the same name. In this case, you have a "min" parameter, which is also a local variable. And later, a couple of lines later, you are trying to declare another local variable, named "min".
Harry Peters wrote: Here is what I did, and BlueJ says I'm missing a return statement.
Well, first, I agree the code doesn't make much sense... but... in terms of the compile error, with Java, when you declare that a method returns a type, it *must* return that a value of that type. And this is true for all possible code paths.
In your code, it is possible for either loop's condition to never be true (as detected at compile time), and hence, the code would end up after the two loops -- and in a section of code, that does not have a return statement. Or in other words, the compiler is complaining that it is possible for the method to execute in a way that doesn't encounter a return statement.