answersLogoWhite

0


Best Answer

In java, a switch statement is used to simplify a long list of 'if' statements. A switch statement takes the form of:

switch (variableName){

case condition1; command1;

case condition2; command2;

...

}

User Avatar

Wiki User

16y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the use of switch statement in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is case in java?

Case is used to label each branch in the switch statement in Java Program


What is the difference between 'switch' statement and 'if' statement?

we can use switch statement in multiple time but in if statement we can not use multiple time


Can a continue statement be used in a switch statement?

If you have a loop in your switch statement or around your switch statement, you can use the continue statement in that. You cannot use a continue statement outside of a loop (do, for, or while).


How if else if statement is differ from switch in general in java?

An else statement is comparing to items, while a switch statement is used to compare multiple items. So if you need multiple results from one statement use a switch but for booleans or very specific functions use a if else statement. Else If ex. if(a=6){System.out.println("It is six");} else(){System.out.println("It is not six");} Switch ex. switch(a){ case 1: System.out.println("it is one"); break; case 2: System.out.println("it is two"); break; default: System.out.println("it is not one or two"); break; } Basically a switch is a good way to check against a lot of possibilities.


What is called OR in Java programming?

If you are going to make an if statement with or, use: Isn't that easy!


What are control structures used in javascript?

The control structures used in java script are if-statement, for-loop, for-in loop, while loop,do-while loop, switch-statement, with-statement. try-catch-finally statements.


The break statement is required in the default case of a switch selection structure?

Ends the case statement. Without it, any code after where the break; is supposed to be will get executed as well until it does encounter a break; or the end of the switch.Code Example:char cTest = 'a';switch(cTest) {case 'a':/* Code here gets executed. */case 'b': //* Code here gets executed. */case 'c':/* Code here gets executed. */break;case 'd':/* Code here won't be executed. */default:/* Code here won't be executed. */}


What programming languages use a C switch statement?

There are two programming languages which use a C switch statement. The two languages are C and C++, hence the name C switch statement. There may be more, but those are the most obvious ones


In java what is the import statement needed to use button components in applets or GUI applications?

I highly recommend you to use javax.swing.JFrame


In command prompt what does the if switch do?

There is not switch called "if". We generally use "if" statement in batch programming in DOS.


How many max no of cases can be written in a switch case?

Java answerThere appears to be no actual limit to the number of cases which can be in a switch statement. However, the size of a method in Java is limited to around 64 KB. This limit would be reached just by writing "case n:" statements about 6,000 times.


What advantage does Java's break statement have over C's break statement?

They do the same thing, but only the former can be used in a Java program.