Tuesday, August 20, 2019

Switch statement

Switch statement:-
1) Switch statement is used to take multiple selections.
2) Curly brasses are mandatory if we are not taking we are getting compilation error.
3) Inside the switch It is possible to declare any number of cases but is possible to declare only one default.
4) Switch is taking the argument the allowed arguments are
a. Byte
b. Short
c. Int
d. Char
e. String(allowed in 1.7 version)
5) Float and double and long is not allowed for a switch argument because these are having more number of possibilities (float and double is having infinity number of possibilities) hence inside the switch statement it is not possible to provide float and double and long as a argument.
6) If the case is matched particular case will be executed if there is no case is matched default case is executed.

Syntax:-
switch(argument)
{
Case label1 : sop(“ “);
break;
Case label2 : sop(“ “);
break;
| |
| |
Default : sop(“ “);
break;
}


Eg:
class Test
{
public static void main(String[] args)
{
int a=10;
switch (a)
{
case 10:System.out.println("10");
break;
case 20:System.out.println("20");
break;
case 30:System.out.println("30");
break;
case 40:System.out.println("40");
break;
default:System.out.println("default");
break;
}
}
};
Output: 10

No comments:

Post a Comment

AME (Approval Management Engine)

AME (Approval Management Engine) : AME Stands for Oracle Approval Management Engine. AME is a self service web application that enables...