開方java
㈠ java怎麼實現開3次方
用Math.pow(double a,double b)方法,方法的參數是被開放數和1/3就可以了。
㈡ Java中求平方以及立方的函數式什麼
Math.pow(x,2)就是平方。Math.pow(x,3)就是立方。
Math.pow(底數,幾次方),如:double a=2.0,double b=3.0,double c=Math.pow(a,b),就是2的三次方是多少;c最終為8。
(2)開方java擴展閱讀:
Math.pow()函數返回基數(base)的指數(exponent)次冪,即base的exponent次冪。Java是一種簡單的,跨平台的,面向對象的,分布式的,解釋的,健壯的安全的,結構的中立的,可移植的,性能很優異的多線程的,動態的語言。
Java編程工具如下:
1、Eclipse:一個開放源代碼的、基於Java的可擴展開發平台 。
2、NetBeans:開放源碼的Java集成開發環境,適用於各種客戶機和Web應用。
3、IntelliJ IDEA:在代碼自動提示、代碼分析等方面的具有很好的功能。
4、MyEclipse:由Genuitec公司開發的一款商業化軟體,是應用比較廣泛的Java應用程序集成開發環境 。
5、EditPlus:如果正確配置Java的編譯器「Javac」以及解釋器「Java」後,可直接使用EditPlus編譯執行Java程序 。
㈢ 關於java開平方函數
你導入錯了唄,sqrt()在lang的Math包里。lang包是默認的,sqrt()方法可能不止一個,對應你那個參數可能就是math包里那個,當然要聲明
㈣ sqrt是什麼意思
1、sqrt是一個「平方根計算」,在VC6.0中的math.h頭文件的函數原型為double sqrt(double)。
2、sqrt在VC6.0中的math.h頭文件的函數原型為double sqrt(double)。它的功能是計算一個非負實數的平方根。
3、sqrt主要的應用就是考驗CPU的浮點能力
(4)開方java擴展閱讀:
1、EXCEL函數:返回正平方根,
2、語法 :SQRT(number)
3、 Numbe:要計算平方根的數。
4、說明:如果參數 Number 為負值,函數 SQRT 返回錯誤值 #Num!。
5、python函數
(1)#!/usr/bin/env python
(2)import math # This will import math mole
(3)print("math.sqrt(100) is:", math.sqrt(100))
㈤ 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