/** * Created by sharanya on 11/30/15. */ import java.awt.*; import javax.swing.*; public class FactorialTest extends JApplet { //An Applet is a mini application. JTextArea outputArea; //This creates a textarea reference // All applets ahould override the init() method. // This method defines what the Applet looks like when it is started up. public void init() { outputArea = new JTextArea(); //create a TextArea object // A Container is a "window". Here, we create a container reference, attach the Applet's content pane to it, and add the text area to it. Container container = getContentPane(); container.add( outputArea ); //We just generate some text to populate the text area with. // calculate the factorials of 0 through 10 for ( long counter = 0; counter <= 10; counter++ ) outputArea.append( counter + "! = " + factorial( counter ) + "\n" ); } // end method init // recursive declaration of method factorial public long factorial( long number ) { // base case if ( number <= 1 ) return 1; // recursive step else return number * factorial( number - 1 ); } // end method factorial }