0
Good afternoon,
I have some strings that come from tests. Example:
String teste2 = (nB < 0.0 && m1 <= j ? "OK" : "Não passa!");
String teste3 = (nB < 0.0 && m2 <= j ? "OK" : "Não passa!");
String teste4 = (nB > 0.0 && m2 <= 35.0 ? "OK" : "Não passa!");
String teste5 = (nB > 0.0 && m2 <= 35.0 ? "OK" : "Não passa!");
I would like to summarize everything in a single string. In this case, if any of the tests showed the message "Don’t pass!" my summary string would return "Don’t pass!" otherwise it would return "OK". The problem is that with the following code it always returns "It doesn’t pass!".
String resultado = (teste2.equals("Não passa!") || teste3.equals("Não passa!") || teste4.equals("Não passa!") || teste5.equals("Não passa!") || teste6.equals("Não passa!") || teste7.equals("Não passa!") || teste8.equals("Não passa!") || teste9.equals("Não passa!") || teste10.equals("Não passa!") ? "Não passa!" : "OK");
What am I doing wrong? Grateful.
In the
teste4, wasn’t meant to usem1instead ofm2?– Victor Stafusa
That will never pass, because the
nb < 0.0ofteste1andteste2contradicts thenb > 0.0ofteste3andteste4.– Victor Stafusa
Because you use
Strings with"OK"and"Não passa!"together with the ternary operator and then goes out doing tests withequalsinstead of simply using thebooleandirectly?– Victor Stafusa