這里有一段代碼,是用遞歸的形式完成數(shù)個for循環(huán)的嵌套,麻煩大家?guī)兔纯慈绾胃膶懗煞沁f歸的代碼并且不用寫成數(shù)個for循環(huán)嵌套。
public class Test {static int i=0; public static void main(String[] args) { int[] counts = new int[3]; counts[0] = 1; counts[1] = 2; counts[2] = 3; dfs(counts, 0);} public static void dfs(int[] counts,int index){ for(int i=0;i<counts[index];i++){ if(index == counts.length-1){System.out.println("hello"); } else{ dfs(counts,index+1); } }}