gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 05:52:30 24 4
gpt4 key购买 nike

以字符串-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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com