title: How do I make this code for censoring words work?
body: <p>I am doing an exercise from my book but it only works partially. It works for one of the three words that I want to censor. I have no idea why it works like that. Here is the code:</p>
  
  <pre><code>public static void main(String[] args){
      String text = "Microsoft announced its next generation Java compiler today. It uses advanced parser and special optimizer for the Microsoft JVM.";
      String forbiddenWords = "Java,JVM,Microsoft";
      String[] words = forbiddenWords.split(",");
      String newText = "";
      for(String word: words){
          System.out.println(word);
      }
  
      for(int i = 0; i &lt; words.length; i++){
          newText = text.replaceAll(words[i], "***");
      }
      System.out.println(newText);
  }
  </code></pre>
  
  <p>And this is what I get for an answer:</p>
  
  <pre><code>*** announced its next generation Java compiler today. It uses advanced parser and special optimizer for the *** JVM.
  </code></pre>
  
  <p>I also have to censor it with the correct amount of <code>*</code> but I don't know how. I know that I am able to get the count of <code>*</code>s by using <code>words[i].length</code> but I don't know how to utilize it.</p>