// Written by: Darren Gates & Ray Klefstad // Date: January 2000 // School: U.C. Irvine import java.awt.*; import java.applet.*; public class RecursionExample extends Applet { public void init() { // These first 2 lines set up the GUI TextArea myTextArea = new TextArea(7, 35); add(myTextArea); String output = ""; for (int n = 0; n < 4; n++) { output += "3 to the power " + n + " is " + power(3, n) + "\n"; } myTextArea.setText(output); } public int power(int x, int n) { return n == 0 ? 1 : x * power(x, n - 1); } }