4
I have a method that will check whether the debt is equal to zero(divida == "0"). If it is he returns true, else it returns false.
Code:
for(String divida : dividas){
return divida == "0";
System.out.println(divida+"\n"+b);
}
return false;
He only returns false, why the first element is non-zero, but the second is equal, and remains false.
What I do?
It continues the same way if the first element (or the one before) is non-zero returns all false.
– lucas daniel
I understood where the error was, is that every time I went to check if it was equal to zero I just checked the first and returned, And the same process always happened.
– lucas daniel
@lucasdaniel added a block
– Reginaldo Soares
But if it returns
falseit will execute another code.– lucas daniel
I would put
return true;inside the block ofifandreturn false;out. With this I do not fall into the bad practice of programming to assign the variable in the condition of theifand I don’t even need that variable. I also don’t needbreak;.– Victor Stafusa