title: Scanner class: Detecting syllables in word
body: <p>I've been creating a Pig Latin translator for a group project for university (we don't have to actually make a translator, just manipulate a string in any way we'd like, and I chose this).</p>
  
  <p>The input into my translator is a Latin prayer, the first two lines of which are:</p>
  
  <pre><code>credo in unum deum 
  patrem omnipotentem 
  </code></pre>
  
  <p>I've created my translator with the following code:</p>
  
  <pre><code>public static void pigLatinify(String fname) throws IOException 
  {
      File file = new File("projectdata.txt");
  
      try 
      {
          Scanner scan1 = new Scanner(file);
          while (scan1.hasNextLine()) 
          {
              Scanner scan2 = new Scanner(scan1.nextLine());
              boolean test2;
              while (test2 = scan2.hasNext())
              {
                  String s = scan2.next();
                  char firstLetter = s.charAt(0);
                  if (firstLetter=='a' || firstLetter=='i' || firstLetter=='o' || firstLetter=='e' || 
                          firstLetter=='u' || firstLetter=='A' || firstLetter=='I' || firstLetter=='O' || 
                          firstLetter=='E' || firstLetter=='U')
                  {
                      String output = s + "hay" + " ";
                      System.out.print(output);
                  }
                      else
                      {
                          String restOfWord = s.substring(1);
                          String output = restOfWord + firstLetter + "ay" + " ";
                          System.out.print(output);
                      }
                  }
                  System.out.println("");
              }
              scan1.close();
          } 
  
          catch (FileNotFoundException e) 
          {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>It outputs the entire prayer well, with the following output for the first two lines:</p>
  
  <pre><code>redocay inhay unumhay eumday 
  atrempay omnipotentemhay
  </code></pre>
  
  <p>However, in true Pig Latin, monosyllabic words stay the same and have "-hay" added to the end, so "it" becomes "ithay", "egg" becomes "egghay", but multi syllabic words have "-way" added to the end instead, so "archery" becomes "archeryway" and "ending" becomes "endingway".</p>
  
  <p>Is there a way for Java (and the scanner class I'm using) to detect if a word is monosyllabic? </p>
  
  <p>At this point I'll also point out I'm only a beginner programmer, so if there is but it is extraordinarily complicated, feel free to just say that!!</p>