switch-case 無 break 如何打印

一、switch-case 無 break 時打印

public class Test {

	public static void main(String[] args) {
		int a = 1;
		switch (a) {
		case 1:
			System.out.println("1");
		case 2:
			System.out.println("2");
		}
	}

}

switch-case 無 break 時打印

二、switch-case 有 break 時打印

public class Test {

	public static void main(String[] args) {
		int a = 1;
		switch (a) {
		case 1:
			System.out.println("1");
			break;
		case 2:
			System.out.println("2");
			break;
		}
	}

}

switch-case 有 break 時打印

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章