

public class CheckValid {



	public  static boolean checkEquation(String equation){
		Stack<Character> stack = new Stack<>(equation.length());
		char top;
		for (int i = 0; i < equation.length(); i++) {
			
			if(equation.charAt(i) =='(' || new Character(equation.charAt(i)).equals('[') || new Character(equation.charAt(i)).equals('{')){
				stack.push(equation.charAt(i));
			}
			
			if(new Character(equation.charAt(i)).equals(')')){
				if(stack.isEmpty())
					return false;
				top=(char)stack.top();
				if(new Character(top).equals('('))
					stack.pop();
				else
					return false;
			}
			
			if(new Character(equation.charAt(i)).equals(']')){
				if(stack.isEmpty())
					return false;
				top=(char)stack.top();
				if(new Character(top).equals('['))
					stack.pop();
				else
					return false;

			}
			
			if(new Character(equation.charAt(i)).equals('}')){
				if(stack.isEmpty())
					return false;
				
				top=(char)stack.top();
				if(new Character(top).equals('{'))
					stack.pop();
				else
					return false;

			}

		}
		if(stack.isEmpty())
			return true;
		else
			return false;
	}



}
