12345
<span style="font-size:14px;">public class Demo01 { public static void main(String[] args) { for(int i = 1;i <= 5; i++){ for (int j = 1; j < 6; j++) { System.out.print(j); } System.out.println(); } } } </span>
11111
22222
33333
44444
55555
<span style="font-size:14px;">public class Demo02 { public static void main(String[] args) { for (int i = 1; i <= 5; i++) { for (int j = 1; j <= 5; j++) { System.out.print(i); } System.out.println(); } } }</span>
3、
1
22
333
4444
55555
<span style="font-size:14px;">public class Demo03 { public static void main(String[] args) { for (int i = 1; i <= 5; i++) { for (int j = 1; j <= i; j++) { System.out.print(i); } System.out.println(); } } }</span>
1
12
123
1234
12345
<span style="font-size:14px;">public class Demo04 { public static void main(String[] args) { for (int i = 1; i <= 5; i++) { for (int j = 1; j <= i; j++) { System.out.print(j + " "); } System.out.println(); } } }</span>
<span style="font-size:14px;">public class Homework { public static void main(String[] args) { for(int i=5;i>0;i--){ for(int j=i-1;j>0;j--){ System.out.print(" "); } for(int j=i;j<5;j++){ System.out.print(j); } for(int j=5;j>=i;j--){ System.out.print(j); } System.out.println(); } System.out.println("=========================="); for(int i = 5;i >= 0;i--){ String txt = ""; for(int k = 1;k < (6 -i);k++){ txt = (6 - k) + txt; } for(int o = txt.length();o < 5;o++){ txt = " " + txt; } txt += new StringBuffer(txt).reverse().toString().substring(1); System.out.println(txt); } } } </span>
原文地址:http://blog.csdn.net/wangshengan/article/details/45743227