Recursive method to print a descending then ascending integer sequence
Assuming you can use a helper function, you could do this:

  public static void writeSequence(int n) {
    if (n &lt; 1) throw new IllegalArgumentException();
    writeSequenceHelper(n);
  }

  public static void writeSequenceHelper(int n) {
    if (n &lt;= 0) return;
    int m = (n+1) / 2;
    System.out.print(m + " ");
    writeSequenceHelper(n - 2);
    System.out.print(m + " ");
  }


If you can't use a helper function like this to workaround the strange IllegalArgumentException requirement, you could do this (which is similar to your solution, but a little more succinct):

  public static void writeSequence2(int n) {
    if (n &lt; 1) throw new IllegalArgumentException();
    if (n == 1) {
      System.out.print("1");
    } else if (n == 2) {
      System.out.print("1 1");
    } else {
      int m = (n+1) / 2;
      System.out.print(m + " ");
      writeSequence2(n - 2);
      System.out.print(" " + m);
    }
  }