I cannot figure out how to prove an existence is true or not;
static boolean existsx(double p1x, double p2x,double[] varray) {
boolean foundx = false;
int i;
//System.out.println(varray.length);
for (double v : varray){
if ( varray[i] > p1x && v < p2x) {
foundx = true;
//System.out.println(x+" was found to be between"+p1x+" and "+p2x);
break;
}
else {
foundx = false;
}
}
return foundx;
}
I’m trying to check for an existence of a number in an array between p1x and p2x. If it is true then, return true, else return false.
I think you have a few logical issues, declaring the variable
iwithout ever initializing it being one of them.The following code should tell you if one of the numbers in the given array is in between those two: