Computer Science, asked by t6719270, 10 hours ago

switch (x) { case 1:System.out .println( “good”);break; case 2:System.out .println( “better”);break; case 3: System.out. println( “best”);break; default: System.out. println( “invalid”); }when x=5​

Answers

Answered by deva1104
1

Answer:Convert the following if else if construct into switch case

Explanation:

By using switch statement instead of if else if construct

switch(var)

{

          case 1:

                System.out.println("good");

                break;

          case 2:

                System.out.println("better");

                break;

          case 3:

                System.out.println("best");

                break;

          default:

                System.out.println("Invalid");

}        

Note

If user need to choose one case among several choices, nested if-else can be used but when number of choices become large, then switch..case is considered as better option as program will be more easier to understand.

Explanation:

Similar questions