import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;
public class Java {
public static int numberOfLoops;
public static int numberOfIterations;
public static int[] loops;
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("N = ");
numberOfLoops = input.nextInt();
System.out.print("K = ");
numberOfIterations = input.nextInt();
input.close();
loops = new int[numberOfLoops];
System.out.println("main START");
nestedLoops(0);
System.out.println("main END");
}
public static void nestedLoops(int currentLoop) {
System.out.println("nestedLoops");
System.out.println("currentLoop " + currentLoop);
if (currentLoop == numberOfLoops) {
printLoops();
return;
}
for (int counter = 1; counter <= numberOfIterations; counter++) {
System.out.println("nestedLoops in LOOP");
System.out.println("currentLoop in LOOP " + currentLoop);
loops[currentLoop] = counter;
nestedLoops(currentLoop + 1);
}
}
public static void printLoops() {
System.out.println("printLoops");
for (int i = 0; i < numberOfLoops; i++) {
System.out.printf("%d", loops[i]);
}
System.out.println();
}
}
こんにちは、みんな。私はここに新しく、これが私の最初の投稿です。
私の質問は:
N = 2 および K = 4 の場合、最初に currentLoop を返した後、1 を続行してメソッド 0 に渡すのはなぜですか?
ありがとう、ニコラ