WHAT IS THE OUTPUT WHEN printNumbers(3) IS CALLED IN:

public void printNumbers(int n)

{

for(int i =1; i<=n-1; i++)

printNumbers(i);

System.out.print(n + " ");

}

I know the answer is 1 1 2 3, but why is it that?

Printable View

- 04-27-2009, 05:24 AMDanKAnother beginner question for AP test
WHAT IS THE OUTPUT WHEN printNumbers(3) IS CALLED IN:

public void printNumbers(int n)

{

for(int i =1; i<=n-1; i++)

printNumbers(i);

System.out.print(n + " ");

}

I know the answer is 1 1 2 3, but why is it that? - 04-27-2009, 05:36 AMFubarable
best to walk through the code on paper and you'll see why.