title: Write a Java program to repeat a String 100 times but add 8 unique typos at 8 random Strings
body: <blockquote>
    <p>A common punishment for school children is to write out a sentence multiple times. Write a Java stand-alone program that will write out the following sentence one hundred times: "I will never spam my friends again." Your program should number each of the sentences and it should make eight different randomlooking typos.</p>
  </blockquote>
  
  <p>This is what i was able to do so far. Unable to get it going together.</p>
  
  <pre><code>public class Punishment {
  
      public static void textgen(int x) {
          System.out.println(x + ") I will never spam my friends again");
      }
  
      public static void main(String[] args) {
          String a = "I will ever spam my friends again.";
          String b = " will never spam my friends again.";
          String c = "I will neer spam my friends again.";
          String d = "I will never pam my friends again.";
          String e = "I will never spam my riends again.";
          String f = "I will never spam my friends gain.";
          String g = "I will never spam y friends again.";
          String h = "I will never sam my friends agn.";
  
          String typos[] = {a,b,c,d,e,f,g,h};
          int[] exitng = new int[8];
  
          ArrayList&lt;Integer&gt; list = new ArrayList&lt;Integer&gt;();
          for (int i=1; i&lt;=100; i++){
              list.add(new Integer(i));
          }
          Collections.shuffle(list);
          for (int i=0; i&lt;8; i++){
              exitng[i] = list.get(i);
              System.out.println( list.get(i)+")- "+typos[i]);
          }
  
          for (int i = 1; i &lt;= 100; i++) {
               textgen(i);
          }
      }
  }
  </code></pre>
  
  <p>Here's an idea:</p>
  
  <pre><code>// initialize result without typos
  String[] sentences = new String[100];
  Arrays.fill(sentences, "I will never spam my friends again.");
  
  // generate 8 unique typo indexes
  Set&lt;Integer&gt; typoIndexes = new HashSet&lt;&gt;();
  while (typoIndexes.size() &lt; 8) {
      typoIndexes.add(Math.random() * 100);
  }
  
  // create a typo at each typo index
  for(int index : typoIndexes) { 
      StringBuilder sb = new StringBuilder(sentences[index]);
      char char1 = char2 = char1;
      int pos1, pos2;
      while (char1 != char2) {
          pos1 = Math.random(sb.length());
          char1 = sb.charAt(pos1);
          pos2 = Math.random(sb.length());
          char2 = sb.charAt(pos2);
      }
      sb.setCharAt(pos1, char2);
      sb.setCharAt(pos2, char1);
      sentences[index] = sb.toString();
  }
  </code></pre>
  
  <p>Note: uncompiled, untested</p>