Skip to main content
edited body
Source Link
Nayuki
  • 1.4k
  • 1
  • 9
  • 20

In your spirit of using only raw arrays and not the collections framework like ArrayList, this is how I would reimplement your even() function:

int[] temp = new int[array.length]; int n = 0; // Prefix length of temp for (int val : array) { if (val % 2 == 0) { temp[n] = val; n++; } } return Arrays.copyOf(temp, jn); // Truncate 

In your spirit of using only raw arrays and not the collections framework like ArrayList, this is how I would reimplement your even() function:

int[] temp = new int[array.length]; int n = 0; // Prefix length of temp for (int val : array) { if (val % 2 == 0) { temp[n] = val; n++; } } return Arrays.copyOf(temp, j); // Truncate 

In your spirit of using only raw arrays and not the collections framework like ArrayList, this is how I would reimplement your even() function:

int[] temp = new int[array.length]; int n = 0; // Prefix length of temp for (int val : array) { if (val % 2 == 0) { temp[n] = val; n++; } } return Arrays.copyOf(temp, n); // Truncate 
deleted 27 characters in body
Source Link
Nayuki
  • 1.4k
  • 1
  • 9
  • 20

In your spirit of using only raw arrays and not the collections framework like ArrayList, this is how I would reimplement your even() function:

int[] temp = new int[array.length]; int jn = 0; // Prefix length of temp for (int i = 0; ival <: array.length; i++) { if (array[i]val % 2 == 0) { temp[j]temp[n] = array[i];val; j++;n++; } } return Arrays.copyOf(temp, j); // Truncate 

In your spirit of using only raw arrays and not the collections framework like ArrayList, this is how I would reimplement your even() function:

int[] temp = new int[array.length]; int j = 0; // Prefix length of temp for (int i = 0; i < array.length; i++) { if (array[i] % 2 == 0) { temp[j] = array[i]; j++; } } return Arrays.copyOf(temp, j); // Truncate 

In your spirit of using only raw arrays and not the collections framework like ArrayList, this is how I would reimplement your even() function:

int[] temp = new int[array.length]; int n = 0; // Prefix length of temp for (int val : array) { if (val % 2 == 0) { temp[n] = val; n++; } } return Arrays.copyOf(temp, j); // Truncate 
Source Link
Nayuki
  • 1.4k
  • 1
  • 9
  • 20

In your spirit of using only raw arrays and not the collections framework like ArrayList, this is how I would reimplement your even() function:

int[] temp = new int[array.length]; int j = 0; // Prefix length of temp for (int i = 0; i < array.length; i++) { if (array[i] % 2 == 0) { temp[j] = array[i]; j++; } } return Arrays.copyOf(temp, j); // Truncate