title: Java Printing a triangle using recursion
body: <p>Assume  the availability of a method  named  <code>makeLine</code> that can be passed a non-negative integer  <code>n</code> and a character  <code>c</code> and return a string  consisting of n identical characters  that are all equal  to <code>c</code>. </p>
  
  <p>Write a method  named  <code>printTriangle</code> that receives two integer  parameters  <code>n</code> and <code>k</code>. If <code>n</code> is negative the method  does nothing. If <code>n</code> happens to be an even number, its value  is raised to the next odd number (e.g. 4-->5). Then, when <code>k</code> has the value  zero, the method  prints a symmetric triangle of <code>O</code>'s (the capital letter <code>O</code>) as follows: first a line of <code>n</code> <code>O</code>, followed by a line of <code>n-2</code> <code>O</code>'s (indented by one space), and then a line of <code>n-4</code> <code>O</code>'s (indented by two spaces), and so on. For example, if the method  received 5,0 (or 4,0) it would print:</p>
  
  <pre><code>OOOOO
   OOO
    O 
  </code></pre>
  
  <p>Note: In the above output, the first line contains 0 spaces before the first <code>O</code>, the next line 1 space, and so on. </p>
  
  <p>Note: These instructions state what the method  does when <code>k</code> is zero, but it is up to you, the programmer, to determine what it does when <code>k</code> is not zero and use it for your advantage. </p>
  
  <p>The method  must not use a loop of any kind (<code>for</code>, <code>while</code>, <code>do</code>-<code>while</code>) to accomplish its job. The method  should invoke <code>makeLine</code> to accomplish the task of creating strings  of varying lengths. </p>
  
  <p>Here is my code:</p>
  
  <pre><code>public void printTriangle(int n, int k) {
  if (n &lt;= 0)
      return;
  
  if(n%2 == 0)
     n++;
  
    System.out.println(makeLine(k, ' ')+ makeLine(n, 'O') +makeLine(k, ' '));
    printTriangle(n-2,k++);
  
  }
  </code></pre>
  
  <p>I'm not sure what I'm doing wrong, can someone help?</p>