Java 计算机的问题 怎么计算复合计算式如:3*5+1=16

来源:百度知道 编辑:UC知道 时间:2024/09/24 01:51:28
public Computer() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c=this.getContentPane();
JButton xx=new JButton("CE");
xx.addActionListener(this);
JPanel jp2=new JPanel();
jtf.setHorizontalAlignment(JTextField.RIGHT);
jp2.setLayout(new GridLayout(1,2));
jp2.add(jtf);
jp2.add(xx);

c.add(jp2,BorderLayout.NORTH);
c.add(jp,BorderLayout.CENTER);
jp.setLayout(new GridLayout(4,4));
String vvt[]={"1","2","3","+","4","5","6","-","7","8","9","*","0",".","=","/"};
for (int i=0;i<16;i++)
{but(vvt[i]);}
}
public static void main(String[] args) {
Computer mf= new Computer();
mf.setBounds(200,200,350,300);
mf.setTi

参照我对另一类似问题的回答吧:
http://zhidao.baidu.com/question/122557036.html

有一种用后缀表达式的方法,先把中缀表达式转换成后缀表达式,再利用栈,计算其值。