当前位置:首页 » 编程语言 » 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

热点内容
王者荣耀服务器地址被屏蔽 发布:2025-04-22 18:46:25 浏览:635
光遇的安卓和苹果有什么区别 发布:2025-04-22 18:46:23 浏览:418
b编译执行 发布:2025-04-22 18:44:13 浏览:454
怎么打开ftp服务 发布:2025-04-22 18:34:42 浏览:149
二级密码什么时候自动消失 发布:2025-04-22 18:32:57 浏览:382
python3withopen 发布:2025-04-22 18:27:57 浏览:682
linuxdelete 发布:2025-04-22 18:25:33 浏览:21
安卓11圆圈什么意思 发布:2025-04-22 18:25:00 浏览:53
安卓微信区怎么登号 发布:2025-04-22 18:08:30 浏览:839
彩票源码公司 发布:2025-04-22 17:47:47 浏览:232