I need a library to be able to parse an equation an give me the result giving the inputs.
For example something like this:
String equation = "x + y + z";
Map<String, Integer> vars = new HashMap<String, Integer>();
vars.add("x", 2);
vars.add("y", 1),
vars.add("z", 3);
EquationSolver solver = new EquationSolver(equation, vars);
int result = solver.getResult();
System.out.println("result: " + result);
And evaluates to:
6
Is there any kind of library for java that can do that for me?
Thanks
You could make use of Java 1.6’s scripting capabilities:
which produces:
For more complex expressions, JEP is a good choice.