如何在Java中提取多项式系数? [英] How to extract polynomial coefficients in Java?

查看:459
本文介绍了如何在Java中提取多项式系数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以字符串 -2x ^ 2 + 3x ^ 1 + 6 为例,介绍如何提取 -2 3 6 从这个等式存储在字符串中?

Taking the string -2x^2+3x^1+6 as an example, how how to extract -2, 3 and 6 from this equation stored in the string?

推荐答案

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

Not giving the exact answer but some hints:

+ - 替换所有 -

使用拆分方法:

// after replace effect
String str = "+-2x^2+3x^1+6"
String[] arr = str.split("+");
// arr will contain: {-2x^2, 3x^1, 6}


  • 现在,每个索引值都可以单独拆分:

  • Now, each index value can be splitted individually:

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


  • 这篇关于如何在Java中提取多项式系数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆