Solving cube root

Source: Internet
Author: User

• Calculate the cubic root of a number without using library functions

Detailed Description:

• Interface Description

Prototype:

public static double Getcuberoot (double input)

Input: Double to solve parameter

Return value: Double the cube root of the input parameter

Input Description:

Parameter double type to solve

Output Description:

The cube root of the input parameter is also a double type

Input Example:
216
Output Example:
6.0

1 ImportJava.util.*;2  3  Public classmain{4      Public Static voidMain (string[] args) {5Scanner cin =NewScanner (system.in);6         7         //Two-point search8          while(Cin.hasnext ()) {9             Doubleinput =cin.nextdouble ();Ten             DoubleMin = 0; One             DoubleMax =input; A             DoubleMID = 0; -              -         //a little more precision to prevent some test cases from failing the              while(Max-min > 0.00001) { -Mid = (min + max)/2; -                   -                 if(Mid*mid*mid >input) { +Max =mid; -}Else  { +Min =mid; A                 } at             } -             //output that satisfies the precision, and the same format number output as the C language -System.out.printf ("%.1f\n", min); -         } -     } -}

Solve cube root

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.