I'm having an issue with incrementing 4 nested while loops. Say you had an array of type double, and many integers to increment the loops. Here's an example
private static double[] approxOfU(double w, double x, double y, double z,
double u) {
double a = 0, b = 0, c = 0, d = 0;
final double[] powerArray = { -5.0, -4.0, -3.0, -2.0, -1, (-1.0 / 2.0),
(-1.0 / 3.0), (-1.0 / 4.0), 0, (1.0 / 4.0), (1.0 / 3.0),
(1.0 / 2.0), 1, 2, 3, 4, 5 };
double[] temp = new double[5];
double approx;
int i = 0, j = 0, k = 0, l = 0;
while (i < powerArray.length) {
a = powerArray[i];
while (j < powerArray.length) {
b = powerArray[j];
while (k < powerArray.length) {
c = powerArray[k];
while (l < powerArray.length) {
d = powerArray[l];
approx = Math.pow(w, a) * Math.pow(x, b)
* Math.pow(y, c) * Math.pow(z, d);
if (Math.abs(approx - u) / u <= 0.01) {
temp[0] = a;
temp[1] = b;
temp[2] = c;
temp[3] = d;
temp[4] = approx;
}
l++;
}
k++;
}
j++;
}
i++;
}
return temp;
}
Where do I put my increments like i++, j++, k++, and l++? The assignment requires only while loops be used on this portion of the project. The for loops part of the project I already got working. Please let me know your thoughts. This code isn't the real code to the assignment but I wanna understand the logic of how to update these nested loops and be able to get the right data from them. When I do output to the screen using the variables below I end up getting 0's so something isn't right. Normally I put the increment by 1 (i++,j++, ... etc) at the end of the curly brace for the loop. In this case that method isn't yielding good results. Please help! :)