public class Du {
public static void main(String[] args) {
int num = 5;//num用来控制你要打印的行数
printDigits(num);
}
private static void printDigits(int num) {
for(int i = 1; i <= num; i++){
for(int 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
for(int i=1;i<=5:i++){
for(int j=1;j<=i;j++){
System.out.print(j+" ");
}
System.out.println();
}
public class Test2 {
public static void main(String[] args) {
int n=8;
List list = new List();
for (int i = 1; i < n; i++) {
int a[] = new int[i-1];
for (int j = 1; j a[j-1]=j;
}
for (int j : a) { //加强for 循环
System.out.print(j);
}
System.out.println();
}
}
}
----------结果-------------------
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
public class e
{
public static void main(String args[])
{
int i,j;
for(i=1;i<6;i++)
{ for(j=1;j<=i;j++)
{
System.out.printf(" "+j);
}
System.out.println(" ");
}
}
}