title: Using recursion, in java, to have a variety of outputs from a single int parameter
body: <p>If anyone is familiar with PracticeIt, it's what I'm doing and I'm on recursion problem sets. I'm having trouble doing them. Here's one problem:</p>
  
  <p><em>Write a method <code>writeSquares</code> that accepts an integer parameter <code>n</code> and prints the first <code>n</code> squares separated by commas, with the odd squares in descending order followed by the even squares in ascending order. The following table shows several calls to the method and their expected output:</em> </p>
  
  <pre><code>   writeSquares(5); ----&gt; Output: 25, 9, 1, 4, 16 
     writeSquares(1); ----&gt; Output: 1
  </code></pre>
  
  <p>I've spent a few hours each day for the past 3 days figuring out recursions but I just can't figure it out. 
  Can anyone point me in the right direction?</p>
  
  <p>My code looks like:</p>
  
  <pre><code>public static void writeSquares(int n)
  {
      if(n&lt;1)
          throw new IllegalArgumentException();
      else{
          if(n%2==0){
              System.out.print((n-1)*(n-1));
              writeSquares2(n-1, n-1, "down");
          }
          else{
              System.out.print(n*n);
              writeSquares2(n-1, n-1, "down");
          }
      }
  }
  
  public static void writeSquares2(int n, int m, String s)
  {
      if(m==0){
          return;
      }
  
      String ss = s;
  
      if(n&lt;=1){
          ss = "up";}
  
      if(n%2==1&amp;&amp;s=="down"){
          System.out.print(", " + n*n);
          writeSquares2(n-2,m-1,ss);
      }
      if(n%2==0&amp;&amp;s=="down"){
          writeSquares2(n-1,m-1,ss);
          System.out.print(", " + n*n);
      }
      if(n%2==1&amp;&amp;s=="up"){
          System.out.print(", " + n*n);
          writeSquares2(n+2,m-1,ss);
      }
      if(n%2==0&amp;&amp;s=="up"){
          writeSquares2(n+1,m-1,ss);
          System.out.print(", " + n*n);
      }
  </code></pre>
  
  <p>EDIT: Woops I fixed the code below</p>
  
  <p>And another question from another problem set is:</p>
  
  <p><em>Write a method <code>writeSequence</code> that accepts an integer <code>n</code> as a parameter and prints a symmetric sequence of <code>n</code> numbers with descending integers ending in <code>1</code> followed by ascending integers beginning with <code>1</code>, as in the table below:</em> </p>
  
  <pre><code>  writeSequence(9);     -----&gt; 5 4 3 2 1 2 3 4 5
    writeSequence(10);    -----&gt; 5 4 3 2 1 1 2 3 4 5
  </code></pre>
  
  <p>My code:</p>
  
  <pre><code>public void writeSequence(int n)
  {
      if(n&lt;1)
          throw new IllegalArgumentException();
      else
          writeSequence2(n, n, "down"); //I actually dont need the second parameter
  }
  
      public void writeSequence2(int n, int m, String s)
      {
          String ss = s;
          if(n/2-1==1)
              ss = "up";
  
          if(n==1)
              System.out.print(n);
  
  
          else if(ss.equals("down")){
              if(n%2==0){
                  System.out.print(n/2+" ");
                  writeSequence2(n-1, m-1, ss);
              }
              else if(n%2==1){
                  writeSequence2(n-1, m-1, ss);
                  System.out.print(" "+ (n/2+1));
              }
  
          }
  
          else if(ss.equals("up")){
              if(n%2==0){
                  System.out.print(n/2+" ");
                  writeSequence2(n-1, m-1, ss);
              }
              else if(n%2==1){
                  writeSequence2(n-1, m-1, ss);
                  System.out.print(" " + (n/2+1));
              }
          }
      }
  </code></pre>
  
  <p>For the second one, my code is somewhat correct. Except when <code>n</code> is odd. 
  Also another question - is it possible to do these with just a <strong>single</strong> method?</p>
  
  <p>Thanks for your time. The tutors in my school aren't very helpful and neither are my classmates.</p>