本文目錄一覽:
java中怎麼用sqrt()
pulic class TestSqrt
{
public static void main(String[] args)
{
System.out.println(“9的平方根是:”+Math.sqrt(9));
}
}
輸出:3.0
Math類在java.lang包下,編譯器默認是導入這個包中的所有類,所以無需導入,並且Math類中的方法全部是靜態的,使用它的方法時無需創建對象,建議你百度”java se 6 api”,一看api文檔你就明白了,祝你好運!
java中如何對一個數開根號
java 中對一個數開根號可以使用系統提供的 Math.sqrt() 函數進行操作
例:
Math.sqrt(3); // 得到結果就是3
java如和開根號
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);
}
原創文章,作者:ZGSZ,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/147087.html