title: How do I exclude inputted punctuation from the user using String Tokenizer?
body: <p>I have seen similar questions to this problem and the answer on the Stack Overflow did not seem to satisfy the problem. I heard that you need to use <code>use.Delimeter</code>, however, I never used it before and want to know how to use it to exclude punctuation from a string that the user inputs. The assignment prompt question is here:</p>
  
  <p>Change the CountWords program (Listing 3.10) so that it does not include punctuation characters in its character count. Hint: You must change the set of delimiters used by the StringTokenizer class.</p>
  
  <p>Here is Listing 3.10:</p>
  
  <pre><code>import java.util.Scanner;
  import java.util.StringTokenizer;
  
  public class ThreeEight {
      public static void main(String[] args) {
          Scanner scan = new Scanner(System.in);
          int wordCount = 0, characterCount = 0;
          String line, word;
          StringTokenizer tokenizer;
          System.out.println("Please enter text (type DONE to quit):");
          line = scan.next();
          while (!line.equals("DONE")) {
              tokenizer = new StringTokenizer(line);
              while (tokenizer.hasMoreTokens()) {
                  word = tokenizer.nextToken();
                  wordCount++;
                  characterCount += word.length();
              }
              line = scan.next();
          }
          System.out.println("Number of words: " + wordCount);
          System.out.println("Number of characters: " + characterCount);
      }
  }
  </code></pre>
  
  <p>Output:</p>
  
  <blockquote>
    <p>Please enter text (type DONE to quit):<br>
        Hello World! @#$%^&amp;<em>():"&lt;>?~/</em>\<br>
        DONE<br>
        Number of words: 3<br>
        Number of characters: 29  </p>
  </blockquote>
  
  <p>As you can see, it does not count punctuation, what code would I use to exclude the punctuation? I used <code>use.Delimeter</code> but it said that it was an invalid method.</p>