給出一個多項式,我試圖編寫代碼來創建一個多項式的程度的推移,和類似的術語相加比如......給的Java:StringTokenizer按照陣列
String term = "323x^3+2x+x-5x+5x^2" //Given
What I'd like = "323x^3+5x^2-2x" //result
到目前爲止,我「已經符號化給定的多項式除以這個...
term = term.replace("+" , "~+");
term = term.replace("-", "~-");
System.out.println(term);
StringTokenizer multiTokenizer = new StringTokenizer(term, "~");
int numberofTokens = multiTokenizer.countTokens();
String[] tokensArray = new String[numberofTokens];
int x=0;
while (multiTokenizer.hasMoreTokens())
{
System.out.println(multiTokenizer.nextToken());
}
從而造成
323x^3~+2x~+x~-5x~+5x^2
323x^3
+2x
+x
-5x
+5x^2
我怎麼會去splitt從x值中選擇係數,將每個係數保存在一個數組中,然後將這些度數放在與係數相同的不同數組中?然後,我將使用此算法添加類似術語....
for (i=0;i<=biggest_Root; i++)
for(j=0; j<=items_in_list ; j++)
if (degree_array[j] = i)
total += b1[j];
array_of_totals[i] = total;
任何和所有的幫助,非常感謝!
我不能很好地理解您的問題 –