首页 > 中学考试杂题 > 题目详情
java计算正余弦值出错代码就是下面的了,所以没有注释运行起来显示没有问题,计算也出结果,可就是不正确./*** @(#
题目内容:
java计算正余弦值出错
代码就是下面的了,所以没有注释
运行起来显示没有问题,计算也出结果,可就是不正确.
/**
* @(#)myfrm.java
*
*
* @author
* @version 1.00 2009/3/23
*/
import java.awt.*;
import java.awt.event.*;
public class myfrm extends Frame{
TextField tf1,tf2;
Button b1,b2,b3;
Label l1,l2;
public myfrm(){
try{
frminit();
}catch(Exception e){
e.printStackTrace();
}
}
private void frminit() throws Exception{
this.setLayout(null);
l1=new Label("Angle:");
l2=new Label("Answer:");
tf1=new TextField("0",4);
tf2=new TextField("1",4);
b1=new Button("Sin");
b2=new Button("Cos");
b3=new Button("Exit");
l1.setBounds(new Rectangle(90,80,40,15));
tf1.setBounds(new Rectangle(130,80,60,15));
l2.setBounds(new Rectangle(250,80,50,15));
tf2.setBounds(new Rectangle(300,80,60,15));
b1.setBounds(new Rectangle(60,120,70,40));
b2.setBounds(new Rectangle(190,120,70,40));
b3.setBounds(new Rectangle(320,120,70,40));
this.add(l1,null);
this.add(l2,null);
this.add(tf1,null);
this.add(tf2,null);
this.add(b1,null);
this.add(b2,null);
this.add(b3,null);
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
b1_actionPerformed(e);
}
});
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
b2_actionPerformed(e);
}
});
b3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
b3_actionPerformed(e);
}
});
}
void b1_actionPerformed(ActionEvent e){
tf2.setText(String.valueOf(
Math.sin(Integer.parseInt((tf1.getText())))));
}
void b2_actionPerformed(ActionEvent e){
tf2.setText(String.valueOf(
Math.cos(Integer.parseInt((tf1.getText())))));
}
void b3_actionPerformed(ActionEvent e){
System.exit(0);
}
public static void main(String args[]){
myfrm myfrm=new myfrm();
myfrm.setTitle("sin and cos coculator");
myfrm.setSize(450,200);
myfrm.show();
}
}
java计算正余弦值出错
代码就是下面的了,所以没有注释
运行起来显示没有问题,计算也出结果,可就是不正确.
/**
* @(#)myfrm.java
*
*
* @author
* @version 1.00 2009/3/23
*/
import java.awt.*;
import java.awt.event.*;
public class myfrm extends Frame{
TextField tf1,tf2;
Button b1,b2,b3;
Label l1,l2;
public myfrm(){
try{
frminit();
}catch(Exception e){
e.printStackTrace();
}
}
private void frminit() throws Exception{
this.setLayout(null);
l1=new Label("Angle:");
l2=new Label("Answer:");
tf1=new TextField("0",4);
tf2=new TextField("1",4);
b1=new Button("Sin");
b2=new Button("Cos");
b3=new Button("Exit");
l1.setBounds(new Rectangle(90,80,40,15));
tf1.setBounds(new Rectangle(130,80,60,15));
l2.setBounds(new Rectangle(250,80,50,15));
tf2.setBounds(new Rectangle(300,80,60,15));
b1.setBounds(new Rectangle(60,120,70,40));
b2.setBounds(new Rectangle(190,120,70,40));
b3.setBounds(new Rectangle(320,120,70,40));
this.add(l1,null);
this.add(l2,null);
this.add(tf1,null);
this.add(tf2,null);
this.add(b1,null);
this.add(b2,null);
this.add(b3,null);
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
b1_actionPerformed(e);
}
});
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
b2_actionPerformed(e);
}
});
b3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
b3_actionPerformed(e);
}
});
}
void b1_actionPerformed(ActionEvent e){
tf2.setText(String.valueOf(
Math.sin(Integer.parseInt((tf1.getText())))));
}
void b2_actionPerformed(ActionEvent e){
tf2.setText(String.valueOf(
Math.cos(Integer.parseInt((tf1.getText())))));
}
void b3_actionPerformed(ActionEvent e){
System.exit(0);
}
public static void main(String args[]){
myfrm myfrm=new myfrm();
myfrm.setTitle("sin and cos coculator");
myfrm.setSize(450,200);
myfrm.show();
}
}
代码就是下面的了,所以没有注释
运行起来显示没有问题,计算也出结果,可就是不正确.
/**
* @(#)myfrm.java
*
*
* @author
* @version 1.00 2009/3/23
*/
import java.awt.*;
import java.awt.event.*;
public class myfrm extends Frame{
TextField tf1,tf2;
Button b1,b2,b3;
Label l1,l2;
public myfrm(){
try{
frminit();
}catch(Exception e){
e.printStackTrace();
}
}
private void frminit() throws Exception{
this.setLayout(null);
l1=new Label("Angle:");
l2=new Label("Answer:");
tf1=new TextField("0",4);
tf2=new TextField("1",4);
b1=new Button("Sin");
b2=new Button("Cos");
b3=new Button("Exit");
l1.setBounds(new Rectangle(90,80,40,15));
tf1.setBounds(new Rectangle(130,80,60,15));
l2.setBounds(new Rectangle(250,80,50,15));
tf2.setBounds(new Rectangle(300,80,60,15));
b1.setBounds(new Rectangle(60,120,70,40));
b2.setBounds(new Rectangle(190,120,70,40));
b3.setBounds(new Rectangle(320,120,70,40));
this.add(l1,null);
this.add(l2,null);
this.add(tf1,null);
this.add(tf2,null);
this.add(b1,null);
this.add(b2,null);
this.add(b3,null);
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
b1_actionPerformed(e);
}
});
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
b2_actionPerformed(e);
}
});
b3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
b3_actionPerformed(e);
}
});
}
void b1_actionPerformed(ActionEvent e){
tf2.setText(String.valueOf(
Math.sin(Integer.parseInt((tf1.getText())))));
}
void b2_actionPerformed(ActionEvent e){
tf2.setText(String.valueOf(
Math.cos(Integer.parseInt((tf1.getText())))));
}
void b3_actionPerformed(ActionEvent e){
System.exit(0);
}
public static void main(String args[]){
myfrm myfrm=new myfrm();
myfrm.setTitle("sin and cos coculator");
myfrm.setSize(450,200);
myfrm.show();
}
}
本题链接: