打印:*****

     ****

     ***

     **

     *

for(int x=1; x<=5; x++) {
    for(int y=x; y<=5; y++) {
        System.out.print("*"); //向下一般的格式for(int y=x; y<=5; y++)
     }
    System.out.println();
}

②打印:*

     **

     ***

     ****

     *****

for (int x=1; x<=5 ;x++ ) {
    for (int y=1;y<=x ;y++ ) {
        System.out.print("*"); //向上一般的格式for(int y=1; y<=x; y++) 
    }
    System.out.println();
}

③打印:* * * * *

       -* * * *

       --* * *

       ---* *

       ----*

for(int x=1; x<=5; x++) {
    for(int y=1; y<x; y++) {
        System.out.print(" "); 先打印" "
    }
    for(int z=x; z<=5; z++) {
        System.out.print("* "); 再打印"*"
    }
    System.out.println();
}

continuebreak

break:跳出。break:结束循环

break作用的范围:要么是switch语句,要么是循环语句。

记住:当break语句单独存在时,下面不要定义其他语句,因为执行不到。

              break跳出所在的当前循环。

如果出现了循环嵌套,break想要跳出指定的循环,可以通过标号来完成。

out:for (int x=0; x<3 ;x++ )

       {

in:for (int y=0; y<4 ; y++)

              {

                     System.out.println("x="+x);

                     break out;               可以对for循环起名字,指定跳出那个循环,

                                        C语言中跳出外循环需要goto语句

              }

       }

continue:继续。作用的范围:循环结构。

       continue:结束本次循环,继续下次循环。break类似可结束外层循环