title: Reducing a nested for loop to a single for loop
body: <p>I am working on some homework for one of my classes and got a problem that I am having some trouble with.  I can't quite figure out how I would do it.  If somebody could point me in the right direction as to how I would go about it that would be great.  Here is the question.</p>
  
  <p>The nested loops</p>
  
  <pre><code>for (int i = 1; i &lt;= height; i++)
  {
      for (int j = 1; j &lt;= width; j++) { System.out.print("*"); }
          System.out.println();
  }
  </code></pre>
  
  <p>display a rectangle of a given width and height, such as</p>
  
  <pre>
  ****
  ****
  ****
  </pre>
  
  <p>Write a single for loop that displays the same rectangle.</p>