在我的一个项目中,我想添加一个用户可以在公式中提供的功能,例如
sin (x + pi)/2 + 1
我在Java应用程序中使用它
/**
* The formula provided by the user
*/
private String formula; // = "sin (x + pi)/2 + 1"
/*
* Evaluates the formula and computes the result by using the
* given value for x
*/
public double calc(double x) {
Formula f = new Formula(formula);
f.setVar("x", x);
return f.calc();
// or something similar
}
如何计算数学表达式?
https://stackoverflow.com/questions/7258538
复制相似问题