//求出e=1+1/1!+1/2!+1/3!+……+1/n!+……的近似值,要求误差小于0.0001import 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("清除"); 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("在文本区输入数字n后回车",10,100); g.drawstring("文本区显示1+1/1!+1/2!+1/3!+……+1/n!+……的近似值",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("请输入数字字符"); } } else if(e.getsource()==button1) { text1.settext("0"); } }}
求出e=1+1/1!+1/2!+1/3!+……+1/n!+……的近似值的java applet程序-JSP教程,Java技巧及代码
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 求出e=1+1/1!+1/2!+1/3!+……+1/n!+……的近似值的java applet程序-JSP教程,Java技巧及代码
相关推荐
- 暂无文章
