- In the following Java code from the 2009 AP CS A multiple choice, students may not be clear that the call
mystery(x / 10)
must resolve entirely beforeSystem.out.print(x % 10)
can execute.
//precondition: x <= 0
public void mystery(int x) {
if ((x / 10) != 0) {
mystery(x / 10);
}
System.out.print(x % 10);
}
- Remember, the simpler you make your examples, the easier it will be for students to focus on understanding the recursion.