Switch

class ClassName {

    public static void main(String[] args){
        new ClassName().methodName();
    }

    void methodName() {

        /* ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ */
        int num = 2;

        switch(num) {
            case 1:
                System.out.println("case1");
            case 2:
                System.out.println("case2");
            case 3:
                System.out.println("case3");
        }
        /* ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ */
    }
}
実行結果
case2
case3

Switch-break

class ClassName {

    public static void main(String[] args){
        new ClassName().methodName();
    }

    void methodName() {

        /* ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ */
        int num = 2;

        switch(num) {
            case 1:
                System.out.println("case1");
                break;
            case 2:
                System.out.println("case2");
                break;
            case 3:
                System.out.println("case3");
                break;
        }
        /* ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ */
    }
}
実行結果
case2

Switch-default

class ClassName {

    public static void main(String[] args){
        new ClassName().methodName();
    }

    void methodName() {

        /* ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ */
        int num = 0;

        switch(num) {
            case 1:
                System.out.println("case1");
                break;
            case 2:
                System.out.println("case2");
                break;
            case 3:
                System.out.println("case3");
                break;
            default:
                System.out.println("default");
        }
        /* ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ */
    }
}
実行結果
default