title: Programmatically format the java code using java
body: <p>I would like to format strings which contains codes like: </p>
  
  <pre><code> "function() { for(i=0;i&lt;n;i++){ return i; }}"
  </code></pre>
  
  <p>The point is to put new lines to each ; except in the for loop, so the formatted output should be something like this:</p>
  
  <pre><code>function() {
     for(i=0;i&lt;n;i++){
      return i;
    } 
   } 
  </code></pre>
  
  <p>Is there any written function for this, or I have to loop through the whole string?</p>