Java: Switch statement

This entry is part 13 of 54 in the series Learn Java

The switch statement checks for equality between an integer and a series of case labels.

It then executes the matching case.

The statement can contain any number of cases and may end with a default label for handling all other cases.

package javaapplication12;

public class JavaApplication12 {

    public static void main(String[] args) {

        int y = 1;

        switch (y) {
            case 0:
                System.out.println(y + " is Zero");
            case 1:
                System.out.println(y + " is One");
                System.out.println(y + " is something else");


Series Navigation<< Java: Array size
Java: Ternary operator (?:) >>

Leave a comment

Leave a Reply