java - Given an array of ints, which is larger between the first and last elements in the array. Return the new array -


in problem need find largest element between first , last element in array, , set other elements in array value , return new array. problem works in arrays of 3 elements. need find way have working given aaray length. have far:

public int[] maxend(int[] a) {      if (a[a.length-1] > a[0]) {          a[0] = a[a.length-1];          a[1] = a[a.length-1];      } else {          a[1] = a[0];          a[a.length-1] = a[0];      }      return a;  } 

didn't test cos i'm on mobile, works.

public int[] maxend(int[] array){         arrays.sort(array);         system.out.println(array[array.length - 1]);         int [] results = new int[array.length];         (int = 0; < array.length; i++){             results[i] = array[array.length - 1];         }         return results;     } 

Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -