Menu
Question Index
...

What will be the output of the following program.

class NumberDescription
{
    public static void main(String s[])
    {
        int number = 5;

        switch(number)
        {
            case 2:
            case 4:
            case 6:
            case 8:
                System.out.println("Even");
                break;
            case 1:
            case 3:
            case 5:
            case 7:
            case 9:
                System.out.println("Odd");
                break;
            case 2:
            case 3:
            case 5:
            case 7:
                System.out.println("Prime");
                break;
            case 4:
            case 9:
                System.out.println("Perfect Square");
                break;
            default:
                System.out.println("Can only describe numbers from 1 to 9");
        }
    }
}


Odd
Compilation Errors
Odd
Prime
Runtime Error

Doubts

Problems

Topic: switch Statement In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App