So far, the user has entered 4 ints that are greater than 1 and positive (relati
ID: 3549885 • Letter: S
Question
So far, the user has entered 4 ints that are greater than 1 and positive (relatively small numbers, about 2-7 digits each). The user has also already entered a mystery number they want the following series to calculate based upon their current numbers (also relatively logical in size). I'm looking for nested while / for loops that use the formula, w^a * x^b * y^c * z^d, where wxyz are the four user entered ints, and abcd are any of the contents of the following array:
double[] exponents = new double[]{-5.0,-4.0,-3.0,-2.0,-1.0,-0.33333,-0.25,
0.0,0.25,0.33333,1.0,2.0,3.0,4.0,5.0};
The goal is to use the formula to check all possibilities / combinations via the nested loops in order to produce a solution number that is as close to the user's mystery number as possible.
Most of this program is already written... I just need the nested loops.
Estimated time to complete: 5-10 mins
This is very short, I just strain my brain with nested loops. This is the best deal for time vs points you will find all day.
Explanation / Answer
import java.Math.*;
int inp = {}; // take x,y,z,w into this array
float prod;
int i = pow(15,4); //15^4 every number xyzw can have any of the 15 numbers as the exponent
// So basically i represents numebr of comibinations
while(i-- > 0){
prod = 1;
for( j = 0;j<4;j++){
for(k=0;k<15;k++){
prod *= pow(inp[j],exponents[k]);
}
compare(prod); // now compare this number as per your requirement
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.