Latest web development tutorials

Java pow() 方法

Java Number類 Java Number類


pow() 方法用於返回第一個參數的第二個參數次方。

語法

double pow(double base, double exponent)

參數

  • base --任何原生數據類型。

  • exponent --任何原生數據類型。

返回值

返回第一個參數的第二個參數次方。

實例

public class Test{
	public static void main(String args[]){
		double x = 11.635;
		double y = 2.76;

		System.out.printf("e 的值为 %.4f%n", Math.E);
		System.out.printf("pow(%.3f, %.3f) 为 %.3f%n", x, y, Math.pow(x, y));
	}
}

編譯以上程序,輸出結果為:

e 的值为 2.7183
pow(11.635, 2.760) 为 874.008

Java Number類 Java Number類