String[][]
을 반환 유형으로 사용하고 발견 된 조합을 인쇄하는 대신 가능한 조합의 배열을 반환하려면 어떻게이 함수를 변경할 수 있습니까?재귀 함수, 결과를 배열로 반환
static void combinations2(String[] arr, int len, int startPosition, String[] result){
if (len == 0){
System.out.println(Arrays.toString(result));
return;
}
for (int i = startPosition; i <= arr.length-len; i++){
result[result.length - len] = arr[i];
combinations2(arr, len-1, i+1, result);
}
}
예 :
combinations2({ "Value1", "Value2", "Value3" }, 2, 0);
{ { "Value1", "Value2" }, {"Value1", "Value3"}, {"Value2", "Value3"} }
메소드에서 반환 할 수있는'String [] []'이 없습니다. – SudoRahul
먼저, 반환 유형을 변경해야합니다. 둘째, 반환 된 배열에 무엇을 넣으려고합니까? – Andrew
발견 된 조합은 어디에 인쇄됩니까? – Ashish