基于java的数学库来处理多个数学场景

时间:2010-10-09 06:48:49

标签: java math

我们计划执行类似于此网站AAAMath中提供的内容。我们想要生成将添加/ mult / div / sub的示例问题(2个数字或3个数字或其中一个数字可以是常量......)。想知道是否有任何库在上述基本数学运算中提供更高级别的抽象(例如,提供一种能够处理2个值,3个值或[随机输入范围] + a的单个方法常数值,给你一组答案。)

3 个答案:

答案 0 :(得分:2)

我喜欢JScience提供的抽象;但是如果你需要评估算术表达式,这个example可以作为指导。

答案 1 :(得分:1)

不确定你在这里得到了什么,但java 5及更高版本有可变方法,这使你很容易做到,例如。

public static int add(int ...addends)
{
    long sum = 0;
    for(int addend : addends)
    {
        sum += addend;
    }
    if (sum > Integer.MAX_VALUE || sum < Integer.MIN_VALUE)
    {
        throw new RuntimeException("summation has over- or underflowed");
    }
    return (int) sum;
}

public static void main(String[] args)
{
    System.out.println("sum is: " + add(10, 11, 1029102, -10));
}

答案 2 :(得分:0)

你可以看看:

http://projects.congrace.de/exp4j/index.html

这是一个简单的数学表达式评估程序,可根据Apache License 2

的条款提供