當前位置:首頁 » 編程語言 » java中根號怎麼表示

java中根號怎麼表示

發布時間: 2023-07-01 16:19:43

『壹』 根號3怎麼打

用WPS文字文檔插入的方法:

1、打開WPS文字,新建一空白文檔。實現在文檔中√3輸入。如下圖:

(1)java中根號怎麼表示擴展閱讀

根號3在計算機中表達為√(3)或√3,先輸入√在輸入3。

『貳』 java中如何對一個數開根號

java 中對一個數開根號可以使用系統提供的Math.sqrt() 函數進行操作

例:

Math.sqrt(3);//得到結果就是3

『叄』 Java中,如何對大數開根號啊!

java中對於大數BigInteger,BigDecimal開根號沒有提供函數,可以參考以下實現方法:

import java.math.BigDecimal;
import java.math.BigInteger;
public class BigSquareRoot {
final static BigInteger HUNDRED = BigInteger.valueOf(100);

public static BigDecimal sqrt(BigDecimal number, int scale, int roundingMode) {
if (number.compareTo(BigDecimal.ZERO) < 0)
throw new ArithmeticException("sqrt with negative");
BigInteger integer = number.toBigInteger();
StringBuffer sb = new StringBuffer();
String strInt = integer.toString();
int lenInt = strInt.length();
if (lenInt % 2 != 0) {
strInt = '0' + strInt;
lenInt++;
}
BigInteger res = BigInteger.ZERO;
BigInteger rem = BigInteger.ZERO;
for (int i = 0; i < lenInt / 2; i++) {
res = res.multiply(BigInteger.TEN);
rem = rem.multiply(HUNDRED);

BigInteger temp = new BigInteger(strInt.substring(i * 2, i * 2 + 2));
rem = rem.add(temp);

BigInteger j = BigInteger.TEN;
while (j.compareTo(BigInteger.ZERO) > 0) {
j = j.subtract(BigInteger.ONE);
if (((res.add(j)).multiply(j)).compareTo(rem) <= 0) {
break;
}
}

res = res.add(j);
rem = rem.subtract(res.multiply(j));
res = res.add(j);
sb.append(j);
}
sb.append('.');
BigDecimal fraction = number.subtract(number.setScale(0, BigDecimal.ROUND_DOWN));
int fracLen = (fraction.scale() + 1) / 2;
fraction = fraction.movePointRight(fracLen * 2);
String strFrac = fraction.toPlainString();
for (int i = 0; i <= scale; i++) {
res = res.multiply(BigInteger.TEN);
rem = rem.multiply(HUNDRED);

if (i < fracLen) {
BigInteger temp = new BigInteger(strFrac.substring(i * 2, i * 2 + 2));
rem = rem.add(temp);
}

BigInteger j = BigInteger.TEN;
while (j.compareTo(BigInteger.ZERO) > 0) {
j = j.subtract(BigInteger.ONE);
if (((res.add(j)).multiply(j)).compareTo(rem) <= 0) {
break;
}
}
res = res.add(j);
rem = rem.subtract(res.multiply(j));
res = res.add(j);
sb.append(j);
}
return new BigDecimal(sb.toString()).setScale(scale, roundingMode);
}

public static BigDecimal sqrt(BigDecimal number, int scale) {
return sqrt(number, scale, BigDecimal.ROUND_HALF_UP);
}

public static BigDecimal sqrt(BigDecimal number) {
int scale = number.scale() * 2;
if (scale < 50)
scale = 50;
return sqrt(number, scale, BigDecimal.ROUND_HALF_UP);
}

public static void main(String args[]) {
BigDecimal num = new BigDecimal("6510354513.6564897413514568413");
long time = System.nanoTime();
BigDecimal root = sqrt(num, 1000);
time = System.nanoTime() - time;
System.out.println(root);
System.out.println(root.pow(2));
System.out.println(time);
}
}
執行結果:
80686.76406162506362881367
6510354513.
46726188

熱點內容
linux改變所有者 發布:2025-02-10 23:04:13 瀏覽:650
源碼曹毅 發布:2025-02-10 23:04:01 瀏覽:582
odbcforsqlserver 發布:2025-02-10 22:26:37 瀏覽:600
區塊鏈數據存儲在那裡 發布:2025-02-10 22:25:48 瀏覽:689
c語言for死循環 發布:2025-02-10 22:24:08 瀏覽:523
蘋果限制訪問初始密碼 發布:2025-02-10 22:21:31 瀏覽:759
為什麼安卓手機一年後卡頓 發布:2025-02-10 22:15:39 瀏覽:732
職工信息管理系統設計c語言 發布:2025-02-10 22:15:30 瀏覽:119
預演算法的理念 發布:2025-02-10 22:15:25 瀏覽:133
如何結合商圈顧客特點配置貨品 發布:2025-02-10 22:10:59 瀏覽:594