How do I give input directly, when that function is invoked in another method, especially when that input is a double[] array?
public double dotPro1(double[] vectorA, double[] vectorB) {
double[] vecPro;
vecPro = new double[2];
vecPro[0] = vectorA[0]*vectorB[0];
vecPro[1] = vectorA[1]*vectorB[1];
return vecPro[0] + vecPro[1];
}
public double dotPro2(double[] length) {
double[] lenPro;
lenPro = new double[1];
lenPro[0] = length[0];
return lenPro[0];
}
public static double cosine(double a) {
double x = Math.cos(Math.toRadians(a));
/*Class c = Class.forName("NaiveStrategy");
Class methodTypes[] = new Class[3];
methodTypes[0] = Double.TYPE;
methodTypes[1] = Double.TYPE;
methodTypes[2] = Double.TYPE;
Method[] m = c.getMethods();*/
NaiveStrategy ns = new NaiveStrategy();
problem-->ns.dotPro1(vectorA[], vectorB[]);
problem-->ns.dotPro2(length[]);
return 0;
}
As you can also see my old coding I tried in another way to solve it, but it didn’t worked. It’s commented out above.
You said in one comment that you want random values. So use the Random class to generate them.
The new double[5]; will create an array of length 5. Change this number to the length you want.
Note: rand.nextdouble only gives a random number between 0 and 1. If you wish it to , say, be between 0 and 100 then use rand.nextDouble()*100
You can then just use