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



