程序未提供所需的输出 [英] Program is not giving desired output
本文介绍了程序未提供所需的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class math
{
JFrame jf;
JTextField jt;
JButton jb;
JButton jb1;
math()
{
jf=new JFrame("frame");
jf.setSize(200,200);
jf.setVisible(true);
jt=new JTextField(50);
jf.setLayout(new FlowLayout());
JButton jb=new JButton("30");
JButton jb1=new JButton("sin");
jb.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
jt.setText("90");
}
});
jb1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
String s=jt.getText();
float x=Float.parseFloat(s);
double s1=Math.sin(x);
String s2=String.valueOf(s1);
jt.setText(s2);
}
});
JButton jb2=new JButton("cos");
jf.add(jt);
jf.add(jb);
jf.add(jb1);
jf.add(jb2);
}
public static void main(String args[])
{
new math();
}
}
//output errors=sin(90)=0.89999 and sin(any angle) is coming incorrect
推荐答案
Math.sin()
接受 PI 表示形式的角度.
Math.sin()
accepts angle in the form of PI representation.
用于获得预期结果
Math.sin(Math.PI/2.0);
这篇关于程序未提供所需的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文