Adam Vinueza
Ranch Hand
Posts: 76
posted 16 years ago
Just for fun, I've decided to make a simple calculator as an exercize. And this got me to wondering the following.
In making a calculator, one needs two strings to hold the input, then convert these strings to integers (I'm making a very simple calculator). But is there a way to take a numberstyle string containing a sign for an arithmetical operation, say, "+", and evaluate the whole thing? E.g., can one construct a mathematical function expression from "7+5"? I've perused the libraries, to no avail, but the libraries are, well, big, so maybe I've missed something.
If not, I guess I'll just have to find out which operator button has been pushed and use the appropriate operation. But it would be nice to do something like the above.
In making a calculator, one needs two strings to hold the input, then convert these strings to integers (I'm making a very simple calculator). But is there a way to take a numberstyle string containing a sign for an arithmetical operation, say, "+", and evaluate the whole thing? E.g., can one construct a mathematical function expression from "7+5"? I've perused the libraries, to no avail, but the libraries are, well, big, so maybe I've missed something.
If not, I guess I'll just have to find out which operator button has been pushed and use the appropriate operation. But it would be nice to do something like the above.
posted 16 years ago
I'm not aware of anything in the standard libraries that do what you want. Making a calculator can be challenging and educational. Do some research on Reverse Polish Notation, infix and postfix notation, and stacks. Good luck.
Junilu
Junilu
Practice only makes habit, only perfect practice makes perfect.
So, practice mindfully. Practice doing the right things and doing things right. — Junilu
[How to Ask Questions] [How to Answer Questions]
manish paliwal
Greenhorn
Posts: 16
posted 16 years ago
You should first learn about Wrapper class. After reading this class i am sure u might be able to solve operation on String(internally integers)
BYE

manish paliwal(or just mann )
BYE

manish paliwal(or just mann )
manish paliwal(or just mann )
It's exactly the same and completely different as this tiny ad:
Thoughts on deprecation in Java
https://coderanch.com/t/683016/java/DeprecationJava
