You shoudl try to make it more clear what you are trying to achieve with your programme and where exactly the problem is. I mean you have 3 If statements.
else if ( (out.equals("(")) || (out.equals("ch"))){
System.out.println("valid");
}
else if ( (out.equals(")")) || (out.equals("ch"))){
System.out.println("invalid");
}
else if ((out.equals ("(")) || (out.equals ("ch"))){
System.out.println("valid");
}
Would I be right in saying that the first and third ones there are the same? In which case drop the third one.
Now if out is ch this will trigger the first condition so it will never go to the second one, I would assume that it can't be valid and invalid at the same time so what is it?
A bit of debugging you could do would be to put some distinctive print statements inside the Ifs to see which ones are being triggered(or use IDE debugging).