我想打印字符的三角形。我想要這樣。在java中打印字符的三角形
A
A B
A B C
A B C D
A B C D E
以下是我的代碼。
public class Pro8Point3
{
public static void main(String[] args){
int space=29;
char ch;
for (int i=1; i<=5; i++) {
ch='A';
//Print spaces in decreasing order. A is at 29th position.
for (int j=1; j<=space; j++) {
System.out.println(" ");
}
//Print Triangle.
for (int k=1; k<=i; k++) {
System.out.print(ch+" ");
ch+=1;
}
space--;
// System.out.println();
}
System.out.println();
}
}
但它不給我慾望輸出。請指導我在這裏犯了什麼錯誤。
如果您還發布了當前的輸出,會更容易。 – johnnyaug