- なあ、再帰関数好きな人いる? パート2 [転載禁止]©2ch.net
892 :デフォルトの名無しさん[]:2015/11/09(月) 00:50:25.68 ID:tkNS1IWM - >>891
再帰でやるにしても配列と序数の管理は必要でしょうに。 引数つまりローカル変数を書き換えていくっしょ。 public class Test { public static void main(String[] args) { int[] a = IntStream.range(0, 10).toArray(); rec_each(a, 0); } static void rec_each(int[] array, int index) { if (array.length <= index) { return; } else { System.out.println(array[index]); rec_each(array, index + 1); } } }
|