题解 | #求解立方根#

求解立方根

http://www.nowcoder.com/practice/caf35ae421194a1090c22fe223357dca

抄袭大佬,需要背公式

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        while (input.hasNextDouble()) {
            double num = input.nextDouble();
            double x = 1.0;
            while (Math.abs(Math.pow(x, 3) - num) > 0.001) {
                x = x - ((Math.pow(x, 3) - num) / (3 * Math.pow(x, 2)));
            }
            System.out.printf("%.1f%n", x);
        }
    }
}
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务