filmov
tv
#3.2 Java Tutorial | Ternary and Switch | Selection Statement

Показать описание
In this lecture we are discussing about:
1)Ternary operator
a)syntax
b)example
2)Switch
a)what is use of switch?
b)Can we use other literal than integer in cases ?
#1
Ternary operator:
:- ternary operator is used to check one condition and store the result in variable.
a)syntax
variable = (condition)? expression1 : expression2;
b)examples
e.g
int num=10;
String str= num%2==0?"Even":"Odd";
int num=2;
int num2=3;
int max=num2num1?num2:num1; (use angled bracket between num2 to num1)
#2
switch
switch in conditional statements used to check multiple condition.
a)Use of Switch
Switch is use to check multiple conditions it is just work same as
to use multiple else if.
example: to show syntax
int num=5;
switch(num){
case 2:
break;
case 5:
break;
default:
}
b)Can we use other literal than character and integer like string
:- you cannot use if you have jdk 1.7 or below then you cannot use switch with string
:- you can use switch with int, char, byte, short, enum, string .
example:
String str="shiva";
switch(str){
case "shiva":
break;
case "harsh":
break;
case "muskan":
break;
default:
break;
}
Note: in further lecture we discussed how modern switch works.
More Learning :
Donation:
PayPal Id : navinreddy20
Patreon : navinreddy20
1)Ternary operator
a)syntax
b)example
2)Switch
a)what is use of switch?
b)Can we use other literal than integer in cases ?
#1
Ternary operator:
:- ternary operator is used to check one condition and store the result in variable.
a)syntax
variable = (condition)? expression1 : expression2;
b)examples
e.g
int num=10;
String str= num%2==0?"Even":"Odd";
int num=2;
int num2=3;
int max=num2num1?num2:num1; (use angled bracket between num2 to num1)
#2
switch
switch in conditional statements used to check multiple condition.
a)Use of Switch
Switch is use to check multiple conditions it is just work same as
to use multiple else if.
example: to show syntax
int num=5;
switch(num){
case 2:
break;
case 5:
break;
default:
}
b)Can we use other literal than character and integer like string
:- you cannot use if you have jdk 1.7 or below then you cannot use switch with string
:- you can use switch with int, char, byte, short, enum, string .
example:
String str="shiva";
switch(str){
case "shiva":
break;
case "harsh":
break;
case "muskan":
break;
default:
break;
}
Note: in further lecture we discussed how modern switch works.
More Learning :
Donation:
PayPal Id : navinreddy20
Patreon : navinreddy20
Комментарии