I have a question on how to call an array static method. In my case, I believe that my array static method is fine because the compiler does not complain about it, but it does when I call it, it says double cannot be converted to double[] How can I fix this? Any help will be greatly appreciated. Below is a snippet of my code:
// create allowed x values for calculation static method
public static double[] allowedValuesX(double[] x, double[] y, int choice){
double allowedVx[] = new double[choice];
int i = 0;
for(i = 0; i < allowedVx.length; i++){
if((Math.pow(x[i], 2) + (Math.pow(y[i], 2))) <= 1){
allowedVx[i] = x[i];
}
}
return allowedVx;
}
// main method
public static void main(String args[]){
// create Scanner object
Scanner in = new Scanner(System.in);
// call to promptUser
promptUser();
// create variable for recieving user input
int choice = in.nextInt();
double x[] = new double[choice];
int i = 0;
for(i = 0; i < x.length; i++){
x[i] = Math.random();
}
// call to allowed x values
allowedValuesX(x[i], y[j], choice);
allowedValuesX(x[i], y[j], choice);vsdouble[] x, double[] y, int choice. Do you see the difference? Your signature expects an array but you're calling it with a single value from the array (aka: a singledouble).