我正在做一个java项目,我有一个让我发疯的循环。
该程序接受一个输入 N,它是一个正整数。我想要我的循环做的是:
假设 N = 10。循环将从 1 到 10 的所有数字,将其提高到五次方,并将每个值存储在长度为 N 的数组中。
我认为它(似乎)可以正常工作,直到N = 73
。一旦N
达到 74 或更高,它就会开始随机给我 74^5 的负数。这显然是不正确的。数字越高,它给我的负面影响就越多。
private static int _theLimit = EquationSolver.getLimit(); //input "N"
private static int length = (int) (_theLimit); //length of possible solutions array = N
static int[] _solutions = new int[length];
public static void solutionRun() {
for(int i = 1; i <=_theLimit ;) {
//theLimit refers to the input N; for numbers from 1 until N
for (int p = 0; p <= _solutions.length-1; p++) {
//solutions is an array that stores all possible solutions to ^5 from 1 to N;
_solutions[p] = i*i*i*i*i;
//p refers to the array location, increments with each new i
i++;
}
}
for(int q = 0; q<=_solutions.length-1; q++){ //outputs solutions for debugging purposes
System.out.println(_solutions[q]);
}
}