This post I tried to print numbers like triangle line-by-line. A little bit fun ^o^
for (i=1;i<=5;i++) {
for (j=1;j<=i;j++) {
System.out.print(j+"_");
}
System.out.println();
}
1_
1_2_
1_2_3_
1_2_3_4_
1_2_3_4_5_
1_2_
1_2_3_
1_2_3_4_
1_2_3_4_5_
for (i=5;i>=1;i--) {
for (j=1;j<=i;j++) {
System.out.print(j+"_");
}
System.out.println();
}
1_2_3_4_5_
1_2_3_4_
1_2_3_
1_2_
1_
1_2_3_4_
1_2_3_
1_2_
1_
for (i=1;i<=5;i++) {
for (j=5;j>=i;j--) {
System.out.print(j+"_");
}
System.out.println();
}
5_4_3_2_1_
5_4_3_2_
5_4_3_
5_4_
5_
5_4_3_2_
5_4_3_
5_4_
5_
for (i=5;i>=1;i--) {
for (j=5;j>=i;j--) {
System.out.print(j+"_");
}
System.out.println();
}
5_
5_4_
5_4_3_
5_4_3_2_
5_4_3_2_1_
5_4_
5_4_3_
5_4_3_2_
5_4_3_2_1_
for (i=1;i<=5;i++) {
for (j=1;j<i;j++) {
System.out.print("_*");
}
for(k=i;k<=5;k++) {
System.out.print(k+" ");
}
System.out.println();
}
1 2 3 4 5
_*2 3 4 5
_*_*3 4 5
_*_*_*4 5
_*_*_*_*5
_*2 3 4 5
_*_*3 4 5
_*_*_*4 5
_*_*_*_*5
for (i=5;i>=1;i--) {
for (j=1;j<i;j++) {
System.out.print("_*");
}
for(k=i;k<=5;k++) {
System.out.print(k+" ");
}
System.out.println();
}
_*_*_*_*5
_*_*_*4 5
_*_*3 4 5
_*2 3 4 5
1 2 3 4 5
_*_*_*4 5
_*_*3 4 5
_*2 3 4 5
1 2 3 4 5
for (i=5;i>=1;i--) {
for (j=5;j>i;j--) {
System.out.print("_*");
}
for(k=i;k>=1;k--) {
System.out.print(k+" ");
}
System.out.println();
}
5 4 3 2 1
_*4 3 2 1
_*_*3 2 1
_*_*_*2 1
_*_*_*_*1
_*4 3 2 1
_*_*3 2 1
_*_*_*2 1
_*_*_*_*1
Sign up here with your email
ConversionConversion EmoticonEmoticon