class ForDemo{
public static void main(String[] args){
for(int x = 1;x<=9;x++){
for(int y = 1;y<=x;y++){ //当X=1时,Y=1,满足y<=x,输出为1*1=1\t,然后Y++,y=2,不满足y<=x,退出内循环,输出换行,进入外循环x++
System.out.print(y+"*"+x+"="+y*x+"\t");//x=2,y=1,满足y<=x,输出1*2=2\t,然后y++,y=2,满足y<=x,输出2*2=4\t,然后y++,y=3,不满足
} //y<=x,退出内循环,输出换行,进入外循环.......
System.out.println();
}
}
}
class WhileDemo{
public static void main(String[] args){
int x = 1;
while(x <= 9){
int y = 1;
while(y <= x){
System.out.print(y+"*"+x+"="+y*x+"\t");
y++;
}
x++;
System.out.println();
}
}
}
class DoWhileDemo{
public static void main(String[] args){
int x = 1;
do{
int y = 1;
do{
System.out.print(y+"*"+x+"="+y*x+"\t");
y++;
}while(y<=x);
System.out.println();
x++;
}while(x<=9);
}
}
do...while先执行一次循环体,然后再判断条件,所以至少执行一次。