Java program use of Switch case, break statement

March 29, 2022 · Team EasyExamNotes · 2 min read (est.) · 0 comments

Share on WhatsApp
PROGRAM:


public class SwitchCase {

            public static void main(String args[])

{
for(int i=0; i<=3; i++)
{
            switch(i)
            {
            case 0:
            System.out.println(“i is 0”);
            break;
            case 1:
            System.out.println(“i is 1”);
            break;
            case 2:
                        System.out.println(“i is 2”);
                        break;
            default:
            System.out.println(“i is greater than 2”);
            }
}
}
           
}

OUTPUT:

i is 0
i is 1
i is 2

i is greater than 2

Discussion

Ask a question, share your thoughts or report an error.

Sign in to participate in the discussion.

Join the discussion