有人可以帮我用java打印以下模式
1
1 22
1 22 333
1 22 333 4444
以下是我写的代码
class output {
public static void main(String args[]){
int i, j, num;
for(i=1; i<5; i++){
num=1;
for(j=1; j<=i; j++)
{
System.out.print(num+ " ");
num++;
//System.out.print(j+1);
}
System.out.print(i++);
System.out.println();
}
}
}
答案 0 :(得分:1)
public class output {
public static void main(String[] args) {
int i, j, k;
for (i = 1; i < 5; i++) {
for (j = 1; j <= i; j++) {
for (k = 1; k <= j; k++) {
System.out.print(j);
}
System.out.print(" ");
}
System.out.println();
}
}
}
输出:
1
1 22
1 22 333
1 22 333 4444
答案 1 :(得分:0)
public class op {
public static void main(String[] args) {
int lim = 10;
for(int i=1 ; i<=lim;i++){
for(int j=1;j<=i;j++){
System.out.print(j);
for(int k=1;k<j;k++){
System.out.print(j);
}
System.out.print(" ");
}
System.out.println();
}
}
}