import java.math.BigInteger;
public class GaayuProbOne {
static void power(int N, int P) {
BigInteger result = new BigInteger("10");
BigInteger res = result.pow(P);
System.out.println(res);
}
static double power1(int N, int P) {
double res =Math.pow(N,P);
return res;
}
public static void main(String[] args) {
int N = 10;
double P = 25*power1(10,25);
System.out.println(P);
int q = (int) P;
power(N, q);
}
}
This code is to calculate 10 25 10 25 program in java.
How to calculate it?
Exception in thread "main" java. lang. Arithmetic Exception: Big Integer would overflow supported range
Is there any method to calculate 10 25 10 25 in a java program?
Note: the question has changed significantly since this answer was posted. It originally asked for a way of computing 10^25 x 10^25.
The code has multiple problems:
power
method ignores the value of N
Math.pow
)int
, when the maximum value of int
is just 2147483647The actual code you need is significantly simpler:
BigInteger
Simple code to do that:
import java.math.BigInteger;
public class Test {
public static void main(String[] args) {
int n = 10;
int p = 25;
BigInteger tmp = BigInteger.valueOf(n).pow(p);
BigInteger result = tmp.multiply(tmp);
System.out.println(result);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.