Java - 最简单的部首形式

发布于 2025-01-05 01:57:29 字数 315 浏览 2 评论 0原文

我试图构建一个程序,将部首变成最简单的部首形式。显然,我没有运气。

我正在寻找一种接受 String 并返回 String 的方法。

输入字符串sqrt[160]。我已经让我的方法取出数值(160)。

现在,我只需要一些东西来分解 160 并返回一个 String ,例如:"4*sqrt[10]"

提前致谢!

注意:

  1. 以上只是一个例子

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:

  1. The above is JUST AN EXAMPLE

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

三生池水覆流年 2025-01-12 01:57:29

对数字进行因式分解,所有具有 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.

瑶笙 2025-01-12 01:57:29

定义“最简单的部首形式”。

从什么时候开始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 that 10.954 != 12.649. Is this a typo? Maybe you meant sqrt(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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文