Java switch statement is used when you have multiple possibilities for the if statement.
The basic format of the switch statement is:
Syntax:
switch(variable)
{
case 1:
//execute your code
break;
case n:
//execute your code
break;
default:
//execute your code
break;
}
After the end of each block it is necessary to insert a break statement because if the programmers do not use the break statement, all consecutive blocks of codes will get executed from each and every case onwards after matching the case block.
0 Comments
If you have any doubts,please let me know