JAVA凡是涉及数学的符号前面都要加MATH。
class A{
public static void main(){
double m=4.0;
double n=Math.sqrt(m);
System.out.println(n);
}
}
java实现开根号的运算:
public static void main(String[] args) { long start = System.currentTimeMillis(); double
target=9876543212345d; double result =sqrt(target);
System.out.println("sqrt耗时:"+(System.currentTimeMillis()-start)+",result:"+result);
start=System.currentTimeMillis();
result =SqrtByBisection(target, 0);
System.out.println("SqrtByBisection耗时:"+(System.currentTimeMillis()
start)+",result:"+result);
start=System.currentTimeMillis();
result = SqrtByNewton(target, 0);
System.out.println("SqrtByNewton耗时:"+(System.currentTimeMillis()
start)+",result:"+result);
}
在Math类里的public static double sqrt(double a);
注解:
Returns the correctly rounded positive square root of a double value. Special cases:
If the argument is NaN or less than zero, then the result is NaN.
If the argument is positive infinity, then the result is positive infinity.
If the argument is positive zero or negative zero, then the result is the same as the argument.
Otherwise, the result is the double value closest to the true mathematical square root of the argument value.
Parameters:
a a value.
Returns:
the positive square root of a. If the argument is NaN or less than zero, the result is NaN.
要注意的是 JAVA凡是涉及数学的符号前面都要加MATH
Math.sqrt();
class A{
public static void main(){
double m=4.0;
double n=Math.sqrt(m);
System.out.println(n);
}
}
Math.sqrt();