System.out.println(Math.pow(input, 1.0/3));

牛顿迭代法

 

import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        double in = sc.nextDouble();
        double res = getCubeRoot(in);
        //保留一位小数
        System.out.println(String.format("%.1f",res));
    }
    public static double getCubeRoot(double input){
        if(input == 0){
            return 0;
        }else{
            double x0,x1;
            x0 = input;
            x1 = (2*x0 + input/x0/x0)/3;
            while(Math.abs(x1 - x0) > 0.000001){
                x0 = x1;
                x1 = (2*x0 + input/x0/x0)/3;
            }
            return x1;
        }

    }
}