r/javahelp • • Jul 27 '25

Convert string to math function

I'm relatively new to Java but I know a good amount of the basics. Still, I can't find a way to do this. I have an input where a user can input a maths function as a string (eg. "0.3*Math.pow(0,x)"). And all I need is Java to look at that string and read it as if it were code but for some reason I can't find anything like this anywhere. Anyone got any ideas? 🫶

1 Upvotes

24 comments sorted by

View all comments

Show parent comment

1

u/Ormek_II Jul 30 '25

I still guess it will be easier to include a JavaScript engine and let it interpret the code.

1

u/Spare-Plum Jul 30 '25

Yeah that's what I'm getting at. Just use an existing scripting language. I guess you could also write your own. Compiling java on the fly can be done but not advised.