首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在Java中计算数学表达式的方法

在Java中计算数学表达式的方法
EN

Stack Overflow用户
提问于 2011-08-31 22:32:59
回答 6查看 81.5K关注 0票数 53

在我的一个项目中,我想添加一个用户可以在公式中提供的功能,例如

代码语言:javascript
复制
sin (x + pi)/2 + 1

我在Java应用程序中使用它

代码语言:javascript
复制
/**
 * 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
}

如何计算数学表达式?

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7258538

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档