import net.objecthunter.exp4j.ExpressionBuilder; import net.objecthunter.exp4j.Expression; import net.objecthunter.exp4j.ValidationResult; import net.objecthunter.exp4j.tokenizer.UnknownFunctionOrVariableException; public class MathExpressionParser { public static void main(String[] args) { try { Expression expression = new ExpressionBuilder("2*x + sin(y)") .variables("x", "y") .build(); expression.setVariable("x", 5.0); expression.setVariable("y", Math.PI); double result = expression.evaluate(); } catch (UnknownFunctionOrVariableException e) { } catch (ValidationResult e) { } } } shell


上一篇:
下一篇:
切换中文