1. 在java中a的n次方怎麼表示

java.lang.Math類有專門的方法來求次方值

方法聲明:Math.pow(double m, double n)

參數說明:m為要求方的數,n為次方數

當然如果你願意也可以自己寫個方法來實現m的n次方,實現起來也相當簡單。
下面是自己寫的例子,我覺得用整數做參數就行了,一般都是整數去求方的。
public static long pow(long m, long n){
long result = 1L; //0次方時為1

for(int=0;i<n;i++){
result *= m; //每次乘上次計算次方的結果

}
return result; //計算好了,返回值

}

2. JAVA中算式的次方怎樣表達

Math.pow(a,b);
a的b次方 記住 a 和 b都是double類型
同樣結果也是double類型

3. java中10的n次方怎麼表示

java中10的n次方的表來示方式源:

  • 方法聲明:Math.pow(double m, double n)

  • 參數說明:m為要求方的數,n為次方數

  • 當然如果你願意也可以自己寫個方法來實現m的n次方,實現起來也相當簡單。

  • 下面是自己寫的例子,我覺得用整數做參數就行了,一般都是整數去求方的。


    public static long pow(long m, long n){


    long result = 1L; //0次方時為1



    for(int=0;i<n;i++){


    result *= m; //每次乘上次計算次方的結果



    }


    return result; //計算好了,返回值



    }

4. java中10的n次方怎麼表示

java中10的n次方的表示方式:

  • 方法聲明:Math.pow(double m, double n)

  • 參數說明:m為要求方的數,n為次方數

  • 當然如果你願意也可以自己寫個方法來實現m的n次方,實現起來也相當簡單。

  • 下面是自己寫的例子,我覺得用整數做參數就行了,一般都是整數去求方的。


    public static long pow(long m, long n){


    long result = 1L; //0次方時為1



    for(int=0;i<n;i++){


    result *= m; //每次乘上次計算次方的結果



    }


    return result; //計算好了,返回值



    }

5. java中一個數的n次方應該怎麼寫

public class Test {
public static void main(String[] args){

double m = 2;
double n = 3;

//使用API,Math.pow(double m,double n) -->> 'm' 的 'n' 次方
System.out.println("使用API:" + Math.pow(m, n));
//通過兩種循環實現的 'm' 的 'n' 次方
System.out.println("使用while實現:" + MToThePowerOfNByWhile(m,n));
System.out.println("使用for實現:" + MToThePowerOfNByFor(m,n));
}
public static double MToThePowerOfNByWhile(double m,double n)
{
double result = 1;
while(n > 0)
{
result *= m;
n--;
}
return result;
}
public static double MToThePowerOfNByFor(double m,double n)
{
double result = 1;
for(int i = 0;i<n;i++)
{
result *= m;
}
return result;
}
}

6. JAVA用循環的方法求次方

public class Test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
//從控制台輸入底數
int a = input.nextInt();
//控制台輸入指數
int b = input.nextInt();
//積
int temp = 1;
for (int i = 0; i < b; i++) {
temp = a*temp;
}
//列印出積
System.out.println(temp);
}

}

7. java 中一個數的n次方怎麼寫

Math.pow(double m, double n)
是求m的n次方的
ps:當然了,你也可以用循環實現^_^

8. 如何使用Java計算次方

計算2的N次方
時間限制: 1000ms內存限制: 65536kB
描述
任意給定一個正整數N(N<=100),計算2的N次方的值。
輸入
輸入只有一個正整數N。
輸出
輸出2的N次方的值。
樣例輸入
5
樣例輸出
32
參考代碼

[java] view plain print?
import java.util.*;
public class Main {
public final static int SIZE = 30;
public static void main(String[] args) throws Exception {
Scanner cin = new Scanner(System.in);
int n = cin.nextInt();
int res[] = new int[SIZE + 1];
int i;
for(i = 0;i < SIZE;++ i){
res[i] = 0;
}
res[0] = 1;
while(n > 0){
for(i = 0;i < SIZE;++ i){
res[i] *= 2;
}
for(i = 0;i < SIZE;++ i){
if(res[i] > 9){
res[i + 1] += res[i] / 10;
res[i] %= 10;
}
}
n --;
}
boolean bl = false;
StringBuffer bf = new StringBuffer();
for(i = SIZE;i >= 0;-- i){
if(res[i] != 0 || bl){
bf.append(res[i]);
bl = true;
}
}
System.out.println(bf);
}
}
根據高位低位改進的代碼:
[java] view plain print?
/*
* Title :power 2
* From :http://blog.csdn.net/binfeihan/article/details/6858655
* Time :2011-10-11 21:10PM
* Author :Eric Zhou,binfeihan
* Email :[email protected]
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(cin.readLine().trim());
System.out.println(my_power_2(n));
//System.out.println(Long.MAX_VALUE);
//System.out.println(Long.MIN_VALUE);
}
public static StringBuffer my_power_2(int N){
StringBuffer v = new StringBuffer("");
long num[] = new long[2];
num[1] = 1;
if(N > 62){
num[0] = 1;
num[0] = num[0]<<(N - 62);
num[1] = num[1]<<62;
String s = String.valueOf(num[1]);
int size = 30,i = 0,j = 0;
long n[] = new long[size + 1];
//System.out.println(num[0]+" "+s);
for(i = s.length() - 1;i >= 0;-- i){
n[j ++] = (long) (num[0] * (s.charAt(i) - '0'));
//System.out.println(n[j - 1]);
}
for(i = 0;i < size;++ i){
while(n[i] > 9){
n[i + 1] += n[i] / 10;
n[i] %= 10;
}
}
boolean bl = false;
for(i = size;i >= 0;-- i){
if(n[i] != 0 || bl){
v.append(n[i]);
bl = true;
}
}
}else{
num[1] = num[1] << N;
v.append(String.valueOf(num[1]));
}
return v;
}
}

9. java語言有什麼函數是求次方的

Math.pow(x,2)是平方。
Math.pow(x,3)就是是立方