急!用Java编写一个嵌套的for循环打印下列图案:

11 21 2 31 2 3 41 2 3 4 5帮帮忙哈!谢谢啊!
2024-11-26 18:42:35
推荐回答(4个)
回答1:

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

回答2:

for(int i=1;i<=5:i++){
for(int j=1;j<=i;j++){
System.out.print(j+" ");
}
System.out.println();
}

回答3:

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

回答4:

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(" ");
}
}
}