title: Programmatically center text output in for loop
body: <p>I'm trying to put out the following pattern of chars:</p>
  
  <pre><code>    x
     xxx
    xxxxx
   xxxxxxx
  xxxxxxxxx
  </code></pre>
  
  <p>And this is what I currently have:</p>
  
  <pre><code>String y = "";
  for(int i = 0; i &lt; 10; i++)
  {
        y="";
        for(int s = 0; s &lt; i; s++)
        {
           y+= "x";
        }
        System.out.println(y);
  }
  </code></pre>
  
  <p>This outputs</p>
  
  <pre><code>x
  xx
  xxx
  xxxx
  xxxxx
  xxxxxx
  xxxxxxx
  xxxxxxxx
  </code></pre>
  
  <p>Which is an approach. I'm well aware of the fact that the target pattern increments two <code>x</code> each execution of the loop, and I know that I have to use blank spaces and insert them. However, I'm stuck with this really simple task.</p>
  
  <p>EDIT: The task is to only use two loops. I thought of a way using three, though, but couldn't straight forwardly figure out a way to use two loops.</p>