title: Adding A New Line Every Three Digits
body: <p>Okay, I am trying to add a new line every three letters. The goal is to have 20 rows of randomized capital letters. With 3 capital letters per row.</p>
  
  <p>I randomized the numbers and then converted them to a string. Then outputted the string. I have 60 random capital letters in one straight String, but I can't figure out how to add new lines, since each letter is randomized I can't tell java what to search for like I did before. I have tried using an if statement and add an "/n" at the end, but it just got messy and difficult. And the operator commands I couldn't figure out how to apply every three letters either.</p>
  
  <p>Here is the code I have so far under the "wrightRandomCodesToFile" </p>
  
  <pre><code>package mp05;
  
  import java.io.File;
  import java.io.FileNotFoundException;
  import java.io.PrintWriter;
  import java.util.Random;
  import java.util.Scanner;
  
  public class Main {
      private static final int PRODUCT_COUNT = 20;
      private static final int CHARACTERS_PER_CODE = 3;
      private static int charA;
      private static int preChars;
      private static String preLetters;
  
      public static void main(String[] args) {
          /* (1) Generate three character alphabetic prefix codes. */
          writeRandomCodesToFile("prefix.txt", 'A', 'Z',
                                CHARACTERS_PER_CODE, PRODUCT_COUNT);
          // when you hit run, there is 3 numbers. six digits though.
  
          /* (2) Generate three character alphabetic suffix codes. */
          writeRandomCodesToFile("suffix.txt", 'A', 'Z',
                                 CHARACTERS_PER_CODE, PRODUCT_COUNT);
  
          /* (3) Generate three character numeric inline codes. */
          writeRandomCodesToFile("inline.txt", '0', '9',
                                 CHARACTERS_PER_CODE,  PRODUCT_COUNT);
  
          /* (4) Merge the two alphabetic and one numeric code to produce the
           * final product code. */
          mergeProductCodesToFile("prefix.txt", "inline.txt", "suffix.txt",
                                  "productCode.txt");
      }// end main()
  
  
      /* (1),(2),(3) Generate the alphanumeric codes. These are three aphanumeric
       * character combinations generated randomly with each character in the
       * range A-Z | 0-9. Thus you will have codes from AAA-ZZZ | 000-999.
       *
       * Write numberOfCodesToGenerate codes to the specified file.
       */
      public static void writeRandomCodesToFile(String codeFile,
                                                char fromChar, char toChar,
                                                int numberOfCharactersPerCode,
                                                int numberOfCodesToGenerate) {
          Random rnd = new Random();
          charA = 65;
          for (int i = 1; i &lt;= 20; i++) {
              try (
                  PrintWriter fout = new PrintWriter(new File("prefix.txt")); //Creates File
              ) {
                  preChars = charA + rnd.nextInt(26);
                  preLetters = String.valueOf((char) preChars);
                  System.out.print(preLetters);    
  
              } catch (FileNotFoundException e) {
                   System.err.println(e.getMessage());
              }
          }
      }// end writeRandomCodesToFile()
  
      /* (4) Merge the two alphabetic and one numeric code to produce the final
       * product code. The final product code will consist of &lt;prefix&gt;&lt;inline&gt;&lt;suffix&gt;.
       * Each code will be in the range AAA000AAA-ZZZ999ZZZ.
       *
       * Merge by using a prefix, an inline and a suffix code from their corresponding
       * files. Each individual code (pre, in, post) is used exactly once, and all values are used.
       *
       * Write these final product codes to the file specified in productFile.
       */
      public static void mergeProductCodesToFile(String prefixFile,
                                                 String inlineFile,
                                                 String suffixFile,
                                                 String productFile) {
  
  
      }// end mergeProductCodesToFile()
  }// end Main
  </code></pre>