I am trying to increment a variable from 0-99, and return the value each time, but I’m unsure how i could do this. This is the code i have so far:
public int getValue()
{
if (currentState == COUNTING)
{
for (int i = 0; i <= 99; i++)
{
value = i;
}
return value;
} else {
return super.getValue();
}
}
I’m not sure how I could modify this, as at the moment it is returning 99. I know why, but do not know how to accomplish what i am trying to do.
Unfortunately, strictly speaking you cannot return multiple values from a method call. A method in Java can only return a single primitive value or Object..
Your code returns 99 because the final ‘value’ of your loop variable ‘i’ is 99 when for loop finishes to execute. Instead you should try returning your values hold in an Integer Array.