中央揃えの三角形と逆さまの三角形を印刷したい。出力はこれでなければなりません。中央揃えの三角形と逆さまの三角形をJavaで印刷
1
121
12321
1234321
123454321
1234321
12321
121
1
その正しく示す数字と三角形の上半分が正しく整列中心が、中央alignment.Belowにおける三角形のその表示されていない下半分は私のコードです。
public class Pro1point1
{
public static void main(String[] args){
int i,j,k,l,space=29;
for(i=1;i<=5;i++){
//First print the upper half triangle.
for(j=1;j<=space;j++){
System.out.print(" ");
}
for(k=1;k<=i;k++){
System.out.print(k);
}
for(l=i-1;l>=1;l--){
System.out.print(l);
}
space--;
System.out.println();
}
//Now Print the lower half triangle.
space=29;
for(i=4;i>=1;i--){
for(j=space;j>=1;j--){
System.out.print("");
}
for(k=1;k<=i;k++){
System.out.print(k);
}
for(l=i-1;l>=1;l--){
System.out.print(l);
}
space++;
System.out.println();
}
}
}
このように表示されます。
ありがとうございました。今働いている。ビット混乱なぜ私たちはスペース= 26を取ったのですか?あなたは私を説明できますか? –
私は私の答えを更新しました.. – sinclair