java如何开根号?

2025-01-01 21:54:29
推荐回答(3个)
回答1:

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

}

回答2:

回答3:

class A{
public static void main(){
double m=4.0;
double n=Math.sqrt(m);
System.out.println(n);
}
}