Java Exercises On Methods
Java Exercises On Methods
1
// Fig. 6.12: FactorialTest.java
// Recursive factorial method
import java.awt.*;
import javax.swing.*;
Container c = getContentPane();
c.add( outputArea );
<html>
<applet code="FactorialTest.class" width=275 height=195>
</applet>
</html>
2
numLabel =
new JLabel( "Enter an integer and press Enter" );
c.add( numLabel );
<html>
<applet code="FibonacciTest.class" width=325 height=75>
</applet>
</html>
3
outputArea = new JTextArea( 2, 20 );
Container c = getContentPane();
c.add( outputArea );
outputArea.setText(
"The square of integer 7 is " + square( 7 ) +
"\nThe square of double 7.5 is " + square( 7.5 ) );
}