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