class yujuqiantao
{
public static void main(String[] args)
{
int z=5;
for (int x=1;x<6 ;x++ )
{
int y=0;
for (y=0;y<z;y++ )
{
System.out.print("*");
}
System.out.println();//只是起到换行的作用
z--;
}
}
}
和这个程序
class yujuqiantao
{
public static void main(String[] args)
{
for (int x=1;x<6 ;x++ )
{
int y=0;
for (y=0;y<5;y++ )
{
System.out.print("*");
}
System.out.println();//只是起到换行的作用
y--;
}
}
}
当然会不一样,第一个程序中第二层循环用z控制,而z开始为5在第一层循环中是执行z--;
第二个程序中第二个循环采用y<5来控制,这是一个恒定值.
故而第一程序每次y最大值递减;第二个始终是5