【发布时间】:2019-05-08 12:53:29
【问题描述】:
我正在尝试从多项式字符串中提取系数和指数,然后将它们存储到一个数组中,以便我可以使用这些数组创建一个新项,我可以对其进行数学运算(例如加、减和乘) )
List<Term> poly = new ArrayList<>;
String poly = "26x^7+5x^6-8x^3-2";
int[] coeff = // Something like using split method here to get coeffs
int[] expo = // Same here but with exponents
for(int i = 0; i < coeffs.length; i++){
poly.add(new Term(coeff[i], expo[i]);
}
问题是,我真的不知道该怎么做。我尝试了很多方法,都导致错误..
【问题讨论】:
-
你的系数和指数总是整数吗?如果没有,您需要将它们存储在浮点数中
-
是的,或者至少这是我们所要求的。
标签: java polynomials exponent coefficients