// Ask E = 1 1/1! 1/2! 1/3! ... 1 / n! ... The approximation of the approximation, the error is less than 0.0001
Import java.applet. *;
Import java.awt. *;
Import java.awt.event. *;
Public Class AT1_1 Extends Applet Implements ActionListener
{
Textfield text1;
Button button1;
Public void init ()
{
Text1 = New TextField ("0", 10);
Button1 = new button; "Clear");
Add (Text1);
Add (Button1);
Text1.addactionListener (this);
Button1.addactionListener (this);
}
Public void start () {}
Public void stop () {}
Public void destory () {}
Public void Paint (Graphics G)
{
g.drawstring ("Enter Number N Recourse in Text Region", 10,100);
g.drawstring ("text area shows 1 1/1! 1/2! 1/3! ... 1 / n! ...... The approximate value", 10, 120);
}
Public Void ActionPerformed (ActionEvent E)
{
IF (E.Getsource () == Text1)
{
Double Sum = 1, A = 1;
INT i = 1;
INT n = 0;
Try
{
n = integer.valueof (Text1.getText ()). INTVALUE ();
While (i <= n)
{
A = a * (1.0 / i);
SUM = SUM A;
i = i 1;
}
SUM = SUM * 10000;
Sum = Math.Round (SUM);
Sum = sum / 10000;
Text1.setText (" SUM);
}
Catch (NumberFormatexception Event)
{
Text1.setText ("Please enter a digital character");
}
}
Else if (E.getsource () == Button1)
{
Text1.setText ("0");
}
}
}