首页 热点专区 义务教育 高等教育 出国留学 考研考公

java如和开根号

发布网友

我来回答

5个回答

热心网友

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();

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com