aspose file tools*
The moose likes Beginning Java and the fly likes Strings to operators? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Strings to operators?" Watch "Strings to operators?" New topic
Author

Strings to operators?

Adam Vinueza
Ranch Hand

Joined: Apr 16, 2001
Posts: 76
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 number-style 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.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4419
    
    5

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 - [How to Ask Questions] [How to Answer Questions]
manish paliwal
Greenhorn

Joined: May 18, 2001
Posts: 16
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 )


manish paliwal(or just mann )
Adam Vinueza
Ranch Hand

Joined: Apr 16, 2001
Posts: 76
Thanks guys, I'll take a look at the things you suggest.
 
Consider Paul's rocket mass heater.
 
subject: Strings to operators?
 
Similar Threads
Command line arguments
Formula Converter
Exam doubt
Sidebar >> OOCalculator >> Design Discussion
Problem with JCreator LE