Skip to content
HopperHopper

100% free

Learn computer science. Free, for everyone.

Study guides, runnable examples, and practice with answers. Go at your own pace, one topic at a time.

  • 53 AP CS A topics
  • Python and TypeScript in 25 days
  • Printable PDFs

Try it

countdown(3)

public static void countdown(int n) {
    if (n == 0) {
        System.out.println("Liftoff!");
    } else {
        System.out.println(n);
        countdown(n - 1);
    }
}

Output

3
2
1
Liftoff!

From AP® CS A Topic 4.16: Recursion