liujijiang

java 学习笔记 --4-- 控制执行流程

2020.03.23

控制执行流程

forEach

package com.company;


public class Main {


    public static void main(String[] args) {
	// write your code here

        for(char i : "jjboy".toCharArray()){
            System.out.println(i);
        }
    }
}


break和continue

break:强行退出循环,不执行省下的语句
continue:停止当前迭代,开始下一次循环的迭代

switch

package com.company;



public class Main {


    public static void main(String[] args) {
	// write your code here

        for(int i=0;i<26;i++){
            int c = i + 'a';

            switch (c){
                case 'u' :
                    System.out.println( c + "vowel");
                    break;
                case 'w' :
                    System.out.println( c + "Sometimes a vowel");
                    break;
                default:
                    System.out.println( c + "consonant");
            }
        }
    }
}


short byte char 默认初始化为int