The thing is that I need to solve problems that have a
String data type
String bla = "5 + 10 - 5"; SystemOutPrintln(Integer.parseInt(bla));
I need to get an answer like
10 . But, the option above will throw an error, since the characters
- are not integers.
How can I solve this kind of problem, or are there other options, I will be grateful for practical advice?
Several solutions are possible:
- Write your own interpreter
- Connect a ready-made interpreter, for example exp4j
- Convert expression to java code (on the fly), compile and execute it
- Generate bytecode using bytecode generation library and execute it like Byte Buddy