title: Equilateral triangle in Java using for loop
body: <p>I am trying to draw an equilateral triangle of asterisk characters but when a user enters row number <em>that</em> row will be drawn as <code>"x"</code> and the whole triangle will be <code>"*"</code> but I have an error in the spaces. </p>
  
  <p>Here is my code: </p>
  
  <pre><code>int number_of_stars = getHeight();
  for (int rows=1; rows &lt;= getHeight(); rows++) 
         {
          for (int spaces=1; spaces &lt;= number_of_stars; spaces++) 
          {
              System.out.print(" ");
          }
  
          if(rows == getRowNum()){
              for (int star=1; star &lt;= rows; star++) 
              {
                  System.out.print("x");
                  System.out.print(" ");
                  }
              System.out.println("");
              rows = getRowNum()+1;
              System.out.print(" ");
              System.out.print(" ");
              System.out.print(" ");
  
          }
          for (int star=1; star &lt;= rows; star++) 
          {
              System.out.print("*");
              System.out.print(" ");
              }
          System.out.println("");
          number_of_stars = number_of_stars - 1;
          }
  </code></pre>
  
  <p>and the output is </p>
  
  <pre><code>      * 
       * * 
      * * * 
     * * * * 
    * * * * * 
   * * * * * * 
  x x x x x x x 
  </code></pre>
  
  <hr>
  
  <pre><code> * * * * * * * * * 
  * * * * * * * * * * 
  </code></pre>
  
  <p>the ninth and tenth rows are incorrect </p>