java - 如何在Java中提取多项式系数?

标签 java string text-parsing polynomial-math

以字符串-2x^2+3x^1+6为例,如何提取-236 来自存储在字符串中的方程式?

最佳答案

没有给出确切的答案,但给出一些提示:

  • 使用replace方法:

    将所有 - 替换为 +-

  • 使用split方法:

    // after replace effect
    String str = "+-2x^2+3x^1+6"
    String[] arr = str.split("+");
    // arr will contain: {-2x^2, 3x^1, 6}
    
  • 现在,每个索引值都可以单独拆分:

    String str2 = arr[0];
    // str2 = -2x^2;
    // split with x and get vale at index 0
    

关于java - 如何在Java中提取多项式系数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13415573/

相关文章:

php - 帮助解析 PHP 中的字符串

math - 计算一串简单的数学表达式

python - NLTK 对结果树进行分块和遍历

Heroku 上的 Java 找不到 Main.class

java - NullPointerException 第 65 行强制关闭 - saveContact(); - 评估一个为 null 的变量 [Noob 警告]

java - AppCompatActivity 和 ActionBarActivity

java - 关于 Java 的 int 的基本问题

python - 将列表与数据框列进行比较并创建带有数字的新列

string - 如何从字符串中删除变音符号(重音符号)?

c# - 存储过程解析器