java forwhileswitch语句持续更新

1.while先判断,再执行;do while先执行,再判断。

2.for的无限循环:for(;;){}

3.java 菱形

public class demo_diamond {
    public static void main(String [] args){
        for(int i=1;i<=4;i++){
            for(int j=1;j<=4-i;j++) {
                System.out.print(" ");
            }
            for(int x=1;x<=2*i-1;x++){
                System.out.print("*");
            }
            System.out.println();



            }
        for(int a=1;a<=3;a++){
            for(int c=1;c<=a;c++) {
                System.out.print(" ");
            }
            for(int b=1;b<=7-2*a;b++){
                System.out.print("*");
            }
            System.out.println();


            }
        }

        }

4.java空心菱形

public class demo_kongdiamond {
    public static void main(String[] args) {
        for (int i = 1; i <= 4; i++) {
            for (int j = 1; j <= 4 - i; j++) {
                System.out.print(" ");
            }
            for (int x = 1; x <= 2 * i - 1; x++) {
                if (x == 1 || x == 2 * i - 1) {
                    System.out.print("*");
                } else {
                    System.out.print(" ");
                }

            }

            System.out.println();


        }

        for (int a = 1; a <= 3; a++) {
            for (int b = 1; b <= a; b++) {
                System.out.print(" ");
            }
            for (int c = 1; c <= 7 - 2 * a; c++) {
                if (c == 1 || c == 7 - 2 * a) {
                    System.out.print("*");
                } else {
                    System.out.print(" ");

                }

            }

            System.out.println();


        }


    }
}

 5.九九乘法表

public class demo1_九九乘法表 {
    public static void main(String[] args){
        for(int i=1;i<=9;i++){
            for(int j=1;j<=i;j++){
                System.out.print(i+"*"+j+"="+(i*j)+"	");
            }
            System.out.println();
        }
    }
}

 6.break与continue

  二者相同:均能用于switch语句与loop语句;

  二者不同:break跳出当前循环,使用标识符能够跳出指定循环;continue终止本次循环,跳过直接开始下一循环。

控制输出次数:

public class demo_连续与终端 {
    public static void main(String[] args){
        int count=0;
        a:for(int i=1;i<=10;i++){
            if (i%3==0){
                //break ;//输出两次
                //continue ;//输出7次
                System.out.println("java");//输出13次
                count++;


            }
            count++;
            System.out.println(count);
            System.out.println("java");
        }
    }
}
原文地址:https://www.cnblogs.com/resort-033/p/12914765.html