Saidi Theory Saidi Theory - 4 years ago 187
Java Question

not equals in java

I have this input " 4+4-(4+4+(4+4)))" in an array of strings "balance array"

I'm trying to execute this code:

String expression = "";
for(int j=2 ; j<balance.length-1 ; j++)
if(!(balance[j].equals("+")) || !(balance[j].equals("-")) || !(balance[j].equals("(")) || !(balance[j].equals(")")))
expression = expression + balance[j];

At the end of the code, expression is supposed to contain "444444", but it is not working.

Am I using the !.equals thing & the || thing in a wrong manner?

I want to combine those 4 statements together using || between them.

Answer Source


if(!((balance[j].equals("+")) || (balance[j].equals("-")) || (balance[j].equals("(")) || (balance[j].equals(")"))))


for(int j=0 ; j<=balance.length-1 ; j++)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download