Java - 最简单的部首形式
我试图构建一个程序,将部首变成最简单的部首形式。显然,我没有运气。
我正在寻找一种接受 String
并返回 String
的方法。
输入字符串
:sqrt[160]
。我已经让我的方法取出数值(160)。
现在,我只需要一些东西来分解 160 并返回一个 String
,例如:"4*sqrt[10]"
提前致谢!
注意:
- 以上只是一个例子
I was trying to build a program that puts a radical into simplest radical form. I, ovbiously, had no luck.
I am looking for a method that takes in a String
and returns a String
.
An input String
: sqrt[160]
. I have already made my method take the numerical value out (160).
Now, I just need something to break 160 up and return a String
like: "4*sqrt[10]"
Thanks in advance!
NOTE:
- The above is JUST AN EXAMPLE
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对数字进行因式分解,所有具有 2 的指数次幂的因数都可以移到平方根之外。将其余部分相乘,该部分将保留在根符号下。
Factorize the number, all factors with the exponent of power of two can be moved outside the square root. Multiply the rest, that will remain under the root symbol.
定义“最简单的部首形式”。
从什么时候开始
sqrt(120) = 4*sqrt(10)
?我的计算器告诉我10.954 != 12.649
。这是拼写错误吗?也许您的意思是sqrt(160)
。是什么让你的表格变得更简单?
方法界面简单;实现的逻辑更难。您必须将平方根符号下的值分解为整数因子并寻找完美的平方根。
Define "simplest radical form".
Since when is
sqrt(120) = 4*sqrt(10)
? My calculator tells me that10.954 != 12.649
. Is this a typo? Maybe you meantsqrt(160)
.What makes your form simpler?
The method interface is easy; the logic to implement is harder. You'll have to break the value under the square root sign into integer factors and look for perfect square roots.