javasin运算代码 java中sin函数算法

JAVA中如何进行正弦和余弦的计算java.lang.Math类
Math中javasin运算代码的方法
double b;
b=sin(double a)返回a角javasin运算代码的三角正弦 。
b=cos(double a)返回a角javasin运算代码的三角余弦 。
java计算机程序中sin如何实现根据泰勒公式:
sin(x)=x-x^3/3! x^5/5! …… (-1)^(n-1)*x^(2n-1)/(2n-1)
可以使用迭代法来求sin了,如果需要精度计算,则需要bigdecimal工具来保存精确的浮点数
用java算sin 30°怎么编啊java的Math类提供了各种常用计算方法 , sin也是其中之一,所以你可以直接用Math.sin来计算正弦值 。
代码如下:
import
java.math.*;
public
class
sin
{
public
static
void
main(String
args[])
{
System.out.println(Math.sin(Math.PI*30/180));
}
}
需要注意的是,参数传入的是PI,所以要先用30除以180获得PI值
Java编写计算器,计算器中计算sin,cos,tan的代码怎么写啊public class SanJiao {
public static void main(String[] args) {
double a = Math.toRadians(90);//把数字90 转换成 90度
System.out.println(Math.sin(a));//计算sin 90度
double b = Math.toRadians(30);
System.out.println(Math.cos(b));
double c = Math.toRadians(20);
System.out.println(Math.tan(c));
}
}
运行输出
1.0
0.8660254037844387
0.36397023426620234
求一个 JAVA 的 科学计算器 的 源代码最好里面有 sin cos 倒数、平方根、平方、立方高级一点的!import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Calculator implements ActionListener
{
String s="",s1;
double d1,d2;
JFrame jf = new JFrame("小计算器by Graduate") ;
JTextField tf = new JTextField();
public void init()//实现计算器界面
{
Container c=jf.getContentPane();
tf.setHorizontalAlignment(JTextField.RIGHT);//文本框
c.add(tf,"North");
JPanel pn3 = new JPanel(new BorderLayout());
c.add(pn3,"Center");
JPanel pn2 = new JPanel();//功能键界面(清除键和关闭键)
pn2.setLayout(new BorderLayout());
JPanel pn1 = new JPanel();//运算界面
pn1.setLayout(new GridLayout(4,4));
pn3.add(pn2,"North");
pn3.add(pn1);
//设置按钮
JButton b = new JButton("CLEAR");
b.setToolTipText("请按清除键!");//设置清零键
b.setForeground(Color.RED);//设置字体颜色
b.setBackground(Color.YELLOW);//设置背景色
b.addActionListener(this);
pn2.add(b,"Center");
b = new JButton("OFF");
b.setToolTipText("请按退出键!");//设置off键,点击退出应用程序b.addActionListener(this);
b.setForeground(Color.RED);//字体颜色
b.setBackground(Color.ORANGE);//背景色
pn2.add(b,"East");
b = new JButton("1");//add butten 1
b.addActionListener(this);
pn1.add(b);
b = new JButton("2");//add butten 2
b.addActionListener(this);
pn1.add(b);
b = new JButton("3");//add butten 3
b.addActionListener(this);
pn1.add(b);
b = new JButton(" ");//add butten
b.setForeground(Color.BLUE);//设置字体颜色
b.addActionListener(this);
pn1.add(b);
b = new JButton("4");//add butten 4
b.addActionListener(this);
pn1.add(b);
b = new JButton("5");//add butten 5
b.addActionListener(this);
pn1.add(b);
b = new JButton("6");//add button 6
b.addActionListener(this);
pn1.add(b);
b = new JButton("-");//add button -
b.setForeground(Color.BLUE);//设置字体颜色
b.addActionListener(this);
pn1.add(b);
b = new JButton("7");//add button 7
b.addActionListener(this);
pn1.add(b);
b = new JButton("8");//add button 8
b.addActionListener(this);
pn1.add(b);
b = new JButton("9");//add button 9
b.addActionListener(this);
pn1.add(b);
b = new JButton("*");//add button *
b.setForeground(Color.BLUE);//设置字体颜色
b.addActionListener(this);
pn1.add(b);
b = new JButton("0");//add button 0
b.addActionListener(this);
pn1.add(b);
b = new JButton(".");//add button .
b.addActionListener(this);
pn1.add(b);
b = new JButton("=");//add button =
b.setForeground(Color.RED);//设置字体颜色
b.addActionListener(this);
pn1.add(b);
b = new JButton("\\");//add button \
b.setForeground(Color.BLUE);//设置字体颜色
b.addActionListener(this);
pn1.add(b);
jf.setSize(300,300);//设置大小
jf.setVisible(true);//设置为可视
}
//处理按钮按下时的动作,进行相应的处理
public void actionPerformed(ActionEvent e)
{
String command = e.getActionCommand();
tf.setText(tf.getText() command);
if(command.equals("CLEAR")) //清零键 按下时返回初始状态
{
s1=null;
s="";
tf.setText("");//记录输入值的变量清空
}
else if(command.equals("OFF")) System.exit(0);//off键 关闭应用程序
else if(!command.equals("*")!command.equals("\\")
!command.equals(" ")!command.equals("-")
!command.equals("="))//判断输入是否为数字
{
if(s1==null)//判断输入是否为第一个
s1 = command;
else s1 =command;
d1 = new Double(s1).doubleValue();//字符串型转换为双精度型,还原输入数字
try
{
if(s.equals(" ")) d1 = d1 d2;//加法运算
else if(s.equals("-")) d1 = d2-d1;//减法运算
else if(s.equals("*")) d1 = d1*d2;//乘法运算
else if(s.equals("\\"))d1 = d2/d1;//除法运算
}
catch(Exception ex)
{
tf.setText("Error");//错误显示"Error"
System.out.println(ex.getMessage());
}
}
else if(!command.equals("=")) //判断输入是否为- * \
{
s = command;
s1 = null;
d2 = d1;
}
else//输入=时,显示运算结果
{
tf.setText(tf.getText() d1);
}
}
public static void main(String [] args)
{
new Calculator().init();
}
}
java中sin怎么实现的啊jdk 装好后会有个src.zip你解压可以看到源代码 。
sin这些一般是用级数来做的 。如果你学过高等数学就知道我在说什么了 你可以看看JNI(java native invocation)很多底层的东西是通过调用非java代码来实现的
【javasin运算代码 java中sin函数算法】javasin运算代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java中sin函数算法、javasin运算代码的信息别忘了在本站进行查找喔 。

    推荐阅读