求解立方根JAVA实现

求解立方根JAVA实现,第1张

求解立方根JAVA实现

package ut.org.demo.controller;

public class HJ107求解立方根
{

public static void main(String[] args) {
double a = 216;
//起点
double first = 1.0;
double resolution = 0.001;
double next = (2 * first) / 3 + a / (3 * first * first);
while (Math.abs(next * next * next - a) > resolution) {
next = (2 * next) / 3 + a / (3 * next * next);
System.out.println(next);
}
}
}

输出结果:
48.458079660335365
32.336048413257366
21.626224274645974
14.571429800581024
10.053386822532781
7.414631307227974
6.252731892895682
6.0100776484658
6.000016888672677
6.000000000047538

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/4971297.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-14
下一篇2022-11-13

发表评论

登录后才能评论

评论列表(0条)

    保存