how add code find , return top 2 values have sorted array. i'm not sure on how go return top 2 maximum values.
double[] array = { 8.4, 9.3, 0.2, 7.9, 3.4}; arrays.sort(doublearray); system.out.printf("%ndoublearray: "); ( double value : doublearray) system.out.printf("%.1f ", value);
try this:
n = doublearray.length; double[] toptwo= new double[2]; toptwo[0] = doublearray[n-1]; toptwo[1] = doublearray[n-2]; return toptwo;
Comments
Post a Comment