谁能帮我将这个 for 循环转换为递归方法:到目前为止,我添加了这两种方法,但我仍然想更改第二个循环。先感谢您。
public void makeDesign1() {
int x;
for (int i = 0; i < 5; i++) // For loop is the one creating the rows
{
for (x = 4; x > i; x--) // Nested loop is the one creating the columns
{
System.out.print("*");
}
System.out.println();
}
System.out.println();
}
public static int makeDesign1Recur(int i) {
if (i == 0) {
return 0;
}
System.out.print("*");
return (makeDesign1Recur(i-1));
}
// How to convert this second loop recursive?
public static void makeDesignRow(int i){
for ( int x = i; x>=0; x--){
makeDesign1Recur(x);
System.out.println("");
}
}
慕容3067478
相关分类