求一个数的立方根算法

计算一个数字的立方根,不使用库函数

详细描述:

接口说明

原型:

public static double getCubeRoot(double input)

输入:double 待求解参数

返回值:double  输入参数的立方根

考点:Math.pow(x,y)这个函数是求xy次方,xy的值都是浮点类型的,而你现在要求的是pow(64,1/3),那么也就是641/3次方。

 DecimalFormat df=new DecimalFormat("0.0");转成小数的形式。

import java.text.DecimalFormat;

import java.util.ArrayList;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

     Scanner sc = new Scanner(System.in);

          double db=sc.nextDouble();

          DecimalFormat df=new DecimalFormat("0.0");

          System.out.println(df.format(Math.pow(db, 1.0/3.0)));

        }   

}  

你可能感兴趣的:(求一个数的立方根算法)