java流程控制

83 阅读1分钟
public class Compound{
    public static void main(String args[]) {
        int x = 10;
        int j = 40;
        {
            int y = 40;
            System.out.println(y);
            int z = 245;
            boolean b;
            {
                b = y > z;
                System.out.println(b);
            }
        }
        String word = "hello word";
        System.out.println(word);
        if (x > j) {
            System.out.println('>');
        }
        if (x < j) {
            System.out.println('<');
        }

        switch (x) {
            case 'a':
                System.out.println('a');
                break;
            case 10:
                System.out.println(10);
                break;
            default:
                System.out.println("other");
        }

        while (x <= j) {
            System.out.println(x);
            x++;
        }

        do {
            System.out.println(x);
            x++;
        } while (x <= j);
        //do{} while 比 while 多循环一次

        for (x = 10; x <= j; x++) {
            System.out.println(x);
        }

        char arr[] = {'a', 'b', 'c', 'd'};
        for(char item : arr){
            System.out.println(item);
        }

        Loop : for (x = 10; x <= j; x++) {
            for (j = 0; j <= 10; j++) {
                if(x == j) {
                    System.out.println("ok");
                    break Loop;
                }
            }
        }


    }
}