help me in this code?
my if else statement was not working properly?
it always show valid?
even the user put an invalid expression?
what was i need to do? to solve it
thanks in advance..
import java.io.IOException;
import java.io.*;
import java.util.Arrays;
 
public class datastruct {
 
 
  public static void main(String[] args) throws IOException {
 
 
  	BufferedReader A = new BufferedReader (new InputStreamReader(System.in));
  	String mathex;
  	String output = "";  
  	String out;
  	System.out.println("Enter a Mathematical Expresion:" );
	mathex = A.readLine();
 
 
    int countOperators = 0;
    int countOperands = 0;
 
 
  for(int i = 0; i < mathex.length(); i++) {
     char ch = mathex.charAt(i);
     out = A.readLine();
 
 
     	 if(ch == '+' || ch == '-' || ch == '*' || ch == '/' || ch == '%') {
       countOperators++;
 
 
     	if ( (out.equals("num"))){
 
		System.out.println("invalid");
	}
	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");
	}
	else {
 
		System.out.println("valid");
	}
 
 
 
    System.out.println("INFIX is: " + mathex );
    System.out.println("POSTFIX is: " + mathex );
    System.exit(0);
 
     } 
     else
     countOperands++;
     }
 
    if((countOperators + 1) != countOperands || mathex.length() == 1){
      System.out.println("INVALID MATHEMATICAL EXPRESSION!!!!!"+ '\n');
    }
 
  	}
  }