how to make this expression 2+6+85-9 with calculator in java?
Printable View
how to make this expression 2+6+85-9 with calculator in java?
Need more info, like is it a command line or GUI calculator, but there's not much anyone can do for you until you post some of your own code and ask specific questions about how to fix or improve it.
Hello.
If you want to evaluate arithmetic expressions you can directly parse the given expression into tokens and compute the answer.
Another much better way is to convert the given expression from infix notation to postfix notation. And then evaluate the postfix notation. You will need to use stack data structure to accomplish this.
Thanks,
Syed.
Yes it is a GUI calculator, and
the code i use to add is :
String a=jTextArea1.getText();
Int ans=0;
For (int i=0; i<a.length; i++) {
if a.charAt(i)=="+") {
double ans1=Integer.parseInt
(a.substring(0,i))+Integer.pa
rseInt(a.substring(i+1),a.length
()));
try {
JTextArea1.append("="+ans1);
Cath (Exception e)
{e.printstacktrace();
}
else
If (.............continuosly for * -
and /
..........like that above