java - Method that creates new array on every call? -
i trying create method creates new array recognizable name every time it's called. it's supposed create arrays of size 2 store 2 double values inside.
public static double[] newarray(double x, double y) { double a[] = new double[2]; a[0] = x; a[1] = y; }
basically this, name of array variable can create multiple arrays same function.
for example first array a, next a1, a2, a3 , forth.
set function this:
public static double[] newarray(double x, double y) { return new double[]{x, y}; }
then call this:
double[] myarray1 = newarray(10d, 20d); double[] myarray2 = newarray(3d, 4d);
Comments
Post a Comment