title: How do I print the characters of a String variable in a diagonal line?
body: <p>How can I take a <code>String</code> variable and print it's contents in a diagonal line downward? Preferably using a <code>for</code> or <code>while</code> loop.</p>
  
  <p>This is the code I have now, which doesn't work as intended:</p>
  
  <pre><code>String str = JOptionPane.showInputDialog("enter a string");
  
  for(int i = 0; i &lt;= str.length(); i++)
     {
        System.out.println(str.charAt(i));
     }
  </code></pre>
  
  <p>This outputs <code>str</code> in a line downwards, but not diagonal. How can I make it look like this:</p>
  
  <pre><code>E
   X
    A
     M
      P
       L
        E
  </code></pre>