So I know that you can use
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("JavaScript");
String infix = "3+2*(4+5)";
System.out.println(engine.eval(infix));
which is all great but what if I wanted to evaluate a variable in that expression call it x and make that a random variable between 0 and 1. This is an idea to evaluate definite integrals using a monte carlo method by using input given by the user. So if we had something like say
String infix = x^2+2;