-5
実際に私は、再帰的に菱形で働いていたが、私の問題を示すと私はここでそれ形状解決方法がわからない..ちょうど私は再帰メソッドでこれを解決する方法を
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
* * * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
* * * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
これは私のコードです:
public static void draw(int shape, int space, PrintWriter output) {
boolean x = true;
if (shape < 1) {
System.out.print("");
} else if (x) {
draw(shape - 2, space - 1, output);
row(shape, space, output);
} else {
row(shape, space, output);
draw(shape - 2, space - 1, output);
}
if (space == shape) {
draw(shape - 2, space - 1, output);
}
}
public static void row(int shape, int space, PrintWriter output) {
for (int i = 0; i < space; i++) {
if (i < space - shape) {
System.out.print(" ");// print space
} else {
System.out.print("* ");//print a star
}
}
System.out.println("");
}
プログラムのJava I/Oおよびサイズダイヤモンド:3、5、7、33
プログラムを実行するとどうなりますか?出力はあなたが望むものとどのように違うのですか?自分のコードをデバッグする方法を学ぶことをお勧めします。 'System.out.println()'を呼び出して実行順序と変数の値を表示したり、IDEからデバッガを使用したりすることができます。 –