title: Balanced Symbol Check using Stack in Java
body: <p>Hey guys so I have an assignment where Im supposed to read a string that the user inputs and check for balanced symbols using a stack. So if the string is "{[()]}" the string is balanced because there is a close for every opening. My thought is to use a loop that checks every character from the string that is given and if the string has an opener such as "([{" then it does stack.push(char) and if the character is a closer ")]}" then I need to use stack.pop(char). The issue im running into is that my professor is forcing me to use a string method and any help ive found online is using a boolean method, id appreciate it if someone could help me out here.</p>
  
  <p>I understand that my code is not working but you can at least get the idea of what my logic is.</p>
  
  <p>import java.util.*;</p>
  
  <p>public class BalancedSymbols {</p>
  
  <pre><code>public static String balancedSymbols(String lineToCheck){ //this is the method that im being forced to use
  
      Stack&lt;String&gt; stack = new Stack&lt;String&gt;();
  
     for (int i = 0; i&lt;lineToCheck.length(); i++){
  
          char x = '(';
          char y = '{';
          char z = '[';
  
          char a;
          a = lineToCheck.charAt(i);
  
          if (a == x){
  
              stack.push(a);
  
          }
  
          if (a == y){
  
              stack.push(a);
  
          }
  
          if (a == z){
  
              stack.push(a);
  
          }
  
  
      }
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Obviously I would do the same for popping except with different symbols.</p>