for(int x=1;x<=4;x++)
{ switch(x)
{case 1:System.out.println("1");break;
case 2:System.out.println("1 2");break;
case 3:System.out.println("1 2 3");break;
case 4:System.out.println("1 2 3 4");break;
}
}
还可以用 break来改变循环
for(int x=1;x<=4;x++)
{
for(int y=1;y<=4;y++)
{ System.out.print(y+" ");
if(x==y)
break;
}
System.out.println();
}
温馨提示:内容为网友见解,仅供参考