How do I make a method that receives from the user a Mathematical function represented by (x) like (x + 2), then receives a number which is (x) .. then return the result !! ..
Asked
Active
Viewed 53 times
-4
-
6You'll need to write an expression parser. This is quite a complicated project for a beginner. – Carcigenicate Nov 09 '18 at 20:32
-
1You should probably implement shunting yard and then build on top of that – Azrael Nov 09 '18 at 20:42
2 Answers
0
Here's a link that gives a example on how to implement the shunting yard algorithm for expression parsing: https://eddmann.com/posts/shunting-yard-implementation-in-java/
You can use the ideas in this to build your expression parser and read the stack of commands using switch statements to perform the operation entered. Good luck on the project!

Tim Hunter
- 242
- 1
- 7
-2
If you mean what i think you do, you just need to make a function with a parameter, do the calculation and return the result.

Ists Cilveks
- 1
- 1