I have this program that gets 2 numbers and an action ("+/*^-")..
I was wondering if there's a way to make that string into an action or do I have to make if's (or switch-case)?
Printable View
I have this program that gets 2 numbers and an action ("+/*^-")..
I was wondering if there's a way to make that string into an action or do I have to make if's (or switch-case)?
If this is a school assignment then an if-else or switch should do it.
Realize though that the switch would need a char not an int.
Otherwise you can have a look at the JavaScript engine shipped with Java 6.
You may want to push and pop operands off a stack if you want to have order of operations ie
Code:2 + 3 * 6 != ( 2 + 3 ) * 6