title: Output an ASCII diamond shape using loops
body: <p>I am trying to write a program in Java that captures an integer from the user (assume data is valid) and then outputs a diamond shape depending on the size of the integer, i.e. User enters <code>5</code>, output would be:</p>
  <pre><code>--*--
  -*-*-
  *---*
  -*-*-
  --*--
  </code></pre>
  <p>So far I have:</p>
  <pre class="lang-java prettyprint-override"><code>if (sqr &lt; 0) {
      // Negative
      System.out.print(&quot;#Sides of square must be positive&quot;);
  }
  if (sqr % 2 == 0) {
      // Even
      System.out.print(&quot;#Size (&quot; + sqr + &quot;) invalid must be odd&quot;);
  } else {
      // Odd
      h = (sqr - 1) / 2; // Calculates the halfway point of the square
      // System.out.println();
      for (j = 0; j &lt; sqr; j++) {
          for (i = 0; i &lt; sqr; i++) {
              if (i != h) {
                  System.out.print(x);
              } else {
                  System.out.print(y);
              }
          }
          System.out.println();
      }
  }
  </code></pre>
  <p>Which just outputs:</p>
  <pre><code>--*--
  --*--
  --*--
  --*--
  --*--
  </code></pre>
  <p>I was thinking about decreasing the value of <code>h</code> but that would only produce the left hand side of the diamond.</p>