Menu
Question Index
...

Compare the programs and choose the most appropriate statement.

class PrintNumbers
{
    public static void main(String s[])
    {
        int number = 3;
        
        if(number == 1)
        {
            System.out.println("One");
        }

        if(number == 2)
        {
            System.out.println("Two");
        }

        if(number == 3)
        {
            System.out.println("Three");
        }
    
    }
}

class PrintNumbers2
{
    public static void main(String s[])
    {
        int number = 3;
        
        switch(number)
        {
            case 1:
                System.out.println("One");
                break;
            case 2:
                System.out.println("Two");
                break;
            case 3:
                System.out.println("Three");
                break;
        }

    }
}


Both programs are same
Both programs are same, but PrintNumbers2 is faster than PrintNumbers1
PrintNumbers1 does not compile
PrintNumbers2 does not compile

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