how to make this expression 2+6+85-9 with calculator in java?
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
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