title: Balanced parenthesis, how to count them?
body: <p>I need to write a java program that tells you if the parenthesis are balanced in a string, I can't find the correct way to do it though.
  I already know I am going to use a loop to count the open and closed parenthesis <code>"(" = 1 and ")" = -1</code> stored in an integer that would come back as <code>0</code> or anything else.</p>
  
  <p>I just don't know how to count the parenthesis that way.</p>
  
  <p>Edit: To be clearer, all i really need is a way to count the parentheses and i am blocked because i can't work with something like : </p>
  
  <p>if (args[i] == '(')   //the interpreter will not let me compare strings with chars
      count++;</p>
  
  <p>Edit 2 : </p>
  
  <pre><code>public class Testing_grounds {
      public static void main(String[] args) {
          String str = args[];
          char RetV[] = str.toCharArray();
          int counter = 0;
          for (int n = 0; n &lt;= RetV.length; n++) {
              if (RetV[n] == '(')
                  counter++;
              else if (RetV[n] == ')')
                  counter--;
          }
          if (counter == 0)
              System.out.println("The parentheses are balenced!");
          else if(counter &lt; 0)
              System.out.println("There are to many closed parenthesis!");
          else if(counter &gt; 0)
              System.out.println("There are to many opened parenthesis!");
      }
  }
  </code></pre>
  
  <p>This is pretty much the code i'm going for (i'm trying to get the toCharArray() method to work but i keep getting class expected error on the 3rd line. That line is there because it won't let me do : args.toCharArray)</p>
  
  <p>Remember that i need to do this with an input and not a string already present in the code.</p>