| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 850 人关注过本帖
标题:台劳公式求COS(X),结果错误
只看楼主 加入收藏
luckylock
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2006-3-20
收藏
 问题点数:0 回复次数:1 
台劳公式求COS(X),结果错误
//题目如下:编写一个application应用程序,利用文本框输入X,然后用下列的台劳公式计算cos(x)的值,
//输出之.台劳公式为:cos(x)=1 - x2/2! + x4/4! - x6/6! + x8/8! - ...

import java.awt.*;
import java.awt.event.*;
public class TaiLao extends Frame implements ActionListener
{ Label promptx,promptResult;
TextField xText;
public TaiLao(String strTitle)
{ super(strTitle);
setLayout(new FlowLayout());
promptx=new Label("请输入一个数x");
xText=new TextField(6);
promptResult=new Label(" ");
add(promptx);
add(xText);
add(promptResult);
xText.addActionListener(this);
pack();
show();
}
public static void main(String[] args)
{ TaiLao frameObj=new TaiLao("请输入X");
frameObj.addWindowFocusListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ System.exit(0);
}

});
}
public void actionPerformed(ActionEvent e)
{
int x,oper=-1;
double deshu=1;
x=Integer.parseInt(xText.getText());
for(int i=1;i<10;i++)
{ deshu+=(double)oper*fenZi(x,2*i)/fenMu(2*i);
oper*=-1;

}
promptResult.setText("cos("+x+")= "+deshu);

}
public static int fenMu(int i)//任意项的分母
{ int j=1,total=1;
for(j=i;j>=1;j--)
{ total*=j;
}
return total;
}
public static int fenZi(int a,int i)//求任意项的分子
{ int total=1;
for(int j=1;j<=i;j++)
{ total*=a;
}
return total;
}
}
//运行结果显然错误了
搜索更多相关主题的帖子: COS 结果 劳公式 
2006-04-09 10:11
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 
那就可能是台劳公式错了

可惜不是你,陪我到最后
2006-04-09 10:58
快速回复:台劳公式求COS(X),结果错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017290 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved