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 ?
谢谢,尼古拉