I get the five double data type values from five different function.Without adding those value into array is there any efficient java code for get the maximum value from that five value set.
double d1=r1.function1();
double d2=r1.function2();
double d3=r1.function3();
double d4=r1.function4();
double d5=r1.function5();
double[] d=new double[5];
for(int i=0:i<5;i++){
d[i]="d"+i;
}
double x=max(d);
public static double max(double[] t) {
double maximum = t[0]; // start with the first value
for (int i=1; i<t.length; i++) {
if (t[i] > maximum) {
maximum = t[i]; // new maximum
}
}
return maximum;
}
Without going this much effort is there any efficient way to get the maximum value from above double type data set? And also when adding value to the loop there also some error represent in d[i]="d"+i;
part. Please provide me better solution.