I was wondering how could you write a recursive method that accepts an integer parameter (n) and writes the following sequence: n, n-1, n-2,n-3,..., 0, ... -(n-3), -(n-2), -(n-1), -n. For example: 5,4,3,2,1,0,-1,-2,-3,-4,-5
What would be the base case for this example? How will the method know when to end?
So far I have:
public static void createSequence(int n) {
if (n== 0)
return;
else{
System.out.println(n);
createSequence(n-1);
}
}
This only creates a sequence of positive integers, how can I fix this code?
createSequence(n - 1)