3 개의 배열을 입력으로 사용하고 각 배열의 요소가 순서대로 배열 된이 메서드 (인터리브)를 만들었습니다. 배열에 요소가없는 경우 "-"가 마지막 배열에 추가됩니다.왜이 방법이 작동하지 않습니까?
예 : 이러한 배열에 - [ "1", "2", "3"], [ "4"], [ "5"; "6"] 메소드가 제공되면이 배열 -
[ "1"; "4"; "5"; "2"; "-"; "6"; "삼"; "-"; "-"]
그러나 이것을 호출 할 때 나는 출력물을 얻지 못하고 있습니다. 당신이 실제로 필요한 것은
static String[] interleave(String[] xs, String[] ys, String[] zs) {
int length1 = xs.length;
int length2 = ys.length;
int length3 = zs.length;
int larLength = 0;
if (((length1 > length2) && (length2 > length3) || ((length1 > length3) && (length3 > length2)))) {
larLength = length1;
}
else if (((length2 > length1) && (length1 > length3) || ((length1 > length3) && (length3 > length2)))) {
larLength = length2;
}
else if ((length3 > length2) && (length2 > length1)) {
larLength = length3;
}
String[] result = new String[larLength*larLength];
for(int i = 0; i < (larLength*larLength - 1); i++) {
if (xs[i] != null) {result[i] = xs[i];}
else {result[i] = "-";}
if (ys[i] != null) {result[i+1] = ys[i];}
else {result[i+1] = "-";}
if (zs[i] != null) {result[i+2] = zs[i];}
else {result[i+2] = "-";}
}
return result;
}
길이 계산이 매우 어려워 보입니다. 단지'3 * max (length1, length2, length3)'이어야합니다. – Thilo
다음 순서로 'result'의 다음 요소에 할당합니다 : 0,1,2,1,2,3,2,3,4, .. –
대부분의 IDE는 중단 점을 배치 할 수있는 디버그 모드를 제공하고 코드를 단계별로 실행하여 수행중인 작업을 확인합니다. http://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.jdt.doc .user % 2Ftasks % 2Ftasks-debug-launch.htm 또는 http://stackoverflow.com/questions/18977397/debug-java-program-step-by-step-in-eclipse – mmcrae