JAVA: VarArgs add variables -
i have method:
public static double[] averages(double[]... input) { double[] result = new double[input.length]; for(int = 0; i< result.length; i++) { result[i] = arrays.stream(input[i]).average().getasdouble(); } homecoming result; } i not know priori how many double arrays should switch method. how can add together method variable double [] loop?
in case i:
arraylist<double[]> sim=new arraylist<double[]>(); arrays.add(new double[]{0.25,0.97,0.47,0.31,0.71}); arrays.add(new double[]{0.51,0.91,0.88,0.12,0.15}); arrays.add(new double[]{0.47,0.71,0.42,0.17,0.71}); arrays.add(new double[]{0.41,0.55,0.53,0.64,0.81}); arrays.add(new double[]{0.91,0.14,0.71,0.11,0.61}); but unfortunately, not know arrays double[] before running program.
should go method averages() 5 double arrays nowadays in arraylist "sim"
i should this:
averages(arrays.get(0),arrays.get(1),arrays.get(2),arrays.get(3),arrays.get(4)) but content dell'arraylist "sim" not know prior execution!
first, made typo, didn't mean:
sim.add(new double[]{0.25,0.97,0.47,0.31,0.71}); would made much more sence.
then can phone call method follows:
double[] results = averages(sim.toarray(new double[]{})); i didn't seek run though, new arrays there because method toarray() returns object[] , not t[] reason.
java
No comments:
Post a Comment