title: Reversing the letters in words in a String
body: <p>I have coded the following solution, and it works, except for when there is punctuation. I was wondering if there are O(1) space complexity and O(length of string) time complexity solutions, without using reverse() method, or anything similar that makes this task too easy. Any answer that can also handle punctuation correctly would be great.</p>
  
  <p>Example:</p>
  
  <p>Given string: "I love chocolate"</p>
  
  <p>Return string should be: "I evol etalocohc"</p>
  
  <p>For clarity, when I say handle punctuation correctly, I mean punctuation should not move around.</p>
  
  <pre><code> // reverse the letters of every word in a sentence (string), and return the result
  
   public static String reverse(String x)
   {
       String[] str = x.split(" ");
  
       StringBuilder rev = new StringBuilder("");
  
       for (int i = 0; i &lt; str.length; i++)
       {
           for (int s = str[i].length()-1; s &gt;= 0; s--)
           {
               rev.append(str[i].charAt(s));
           }
           rev.append(" ");
       }
  
       return rev.toString();
   }
  </code></pre>
  
  <p>Here is my output for some tests of mine:</p>
  
  <pre><code>     public static void main(String[] args)
       {
           System.out.println(reverse("I love chocolate"));//this passes
           System.out.println(reverse("Geeks for Geeks"));//this passes
           System.out.println(reverse("You, are awesome"));//not handling puncutation mark correctly, gives me ",uoY era emosewa", instead of "uoY, era emosewa"
           System.out.println(reverse("Geeks! for Geeks."));//not handling puncutation marks correctly, gives me "!skeeG rof .skeeG", instead of "skeeG! rof skeeG."
       }
  </code></pre>