title: How to count number of characters in a string
body: <p>I am trying to count the amount of 'x' characters that are in a string, and print out the number. I end up just counting the number of characters in the string instead. Here is what I have tried:</p>
  
  <pre><code>int count = 0;
  
  for (int j = 0; j &lt; input1.length(); j++)
  {
    char character = input1.charAt(j);
    count++;
  }
  
  if (indexX != -1)
    {
       System.out.println("x count: "+count);
    } // indexX = input1.indexOf('x');
  </code></pre>