См. Комментарии ниже.
public static String [] mergeStrings(String [] x, String [] y) {
//You declared the array that has enough size to wraph both x and y arrays. Good.
String[] result = new String[x.length + y.length];
// get the size of the bigger array?
int largest = (x.length > y.length) ? x.length : y.length;
//If x.length is bigger, this will iterate x.length times, y.length otherwise..
for (int i = 0; i < largest; i++){
//even if you used result[i]=x[i] you would be missing elements for y.
}
}
Я думаю, что вы пытаетесь сделать что-то вроде этого:
public static String[] mergeStrings(String[] x, String[] y) {
//Declare the result string with the sum of sizes.
String[] result = new String[x.length + y.length];
//Assign `x` values to result.
for (int i = 0; i < x.length; i++) {
result[i] = x[i];
}
//Assign `y` values to result. Using resultIndex to start on the first empty position while `i` will be the index for the `y` array.
for (int i = 0, resultIndex = x.length; i < y.length; i++, resultIndex++) {
result[resultIndex] = y[i];
}
return result;
}
Что самое большое для? – hasan83
Почему бы не использовать 'Arrays.sort'? – chrylis
Вам понадобится какой-то бинарный алгоритм поиска/сортировки, чтобы определить индекс наилучшего местоположения для размещения каждого элемента в новом массиве, предполагая, что вы не хотите просто добавлять один массив к другому и сортировать результат ... – MadProgrammer