title: Using java, how do count the occurrences of a character in a string, and then format an output with text listing the locations using loops
body: <p>I understand how to count the occurrences of specific characters in a string. What I am struggling is printing "The specific character is at location x, y, z". If I place the text within the loop that tests for location, the text is printed multiple times. I do not want that to happen.</p>
  
  <p>There are other constraints as well. I must keep the program basic, and I am limited to using the charAt() and string.lenghth() functions. The program should only exit when the user enters "-1". When the user enters the string, the program should read through the characters, output the location of the specific characters, and then prompt the user to enter a new string. I am also struggling with allowing the user to enter a new string and running the loop again.</p>
  
  <p>Here is the code I have so far</p>
  
  <pre><code>import java.util.Scanner;
  
  public class GimmeAW {
  public static void main(String[] args) {
  
      Scanner input = new Scanner(System.in);
      System.out.println("Enter the Line\nEntering -1 exits the program")           
      String aLine;
  
      aLine = input.nextLine();
      char one = aLine.charAt(0);
      char two = aLine.charAt(1);
  
      if (one == '-' &amp;&amp; two == '1') {
          System.out.println("System Exit");
          System.exit(1);
      }
  
      for (int i = 0; i &lt; aLine.length(); i++) {
  
          if (aLine.charAt(i) == 'w' || aLine.charAt(i) == 't') {
              int location = i;
              System.out.print(" " + i);
          }
      }
  }
  </code></pre>