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)就是是立方