#3.2 Java Tutorial | Ternary and Switch | Selection Statement

preview_player
Показать описание
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
Рекомендации по теме
Комментарии
Автор

Very nice explanatiin Sir.. specially when u r frst showing that wht prob can arise if we dont put break and all.
Great work doing sir..
Thank you so much

meghajha
Автор

You are a very nice mentor!! Please keep educating the psyches around the world!!!

darpananeja
Автор

sir can u please give us some coding exercise also, after each lecture for better understanding and in next lecture provide solution of questions, not all but some which u think difficuklt.

rajanyadav
Автор

Very practical and easy to understand explanation! Thank you. Keep on...

vladanulardzic
Автор

Sir i simple say that your awesome....explaining..thank u

JAFFAR
Автор

thanks a lot sir u helped me a lot for my exam

silentium
Автор

Is this for Java 8 or 9?
Will you also show new things like Streams and Jigsaw?
And like Rajan said, you should have like 3-5 excersise questions.

seventeen
Автор

Sir, Please upload video on Data Structure like implementation of BST in Java.

AkshayGuptaMe
Автор

R R VERY INTELLIGENT SIR...I WANT TO BE LIKE U

faheemahmad
Автор

Not only no's Shall we use characters in the ternary statements sir....?

vyshnavidandagula
Автор

one question for you, can I learn machine learning with java its a better option

harshitrawat
Автор

sir, which software are u using. plz tell, i too need to make programs. m in std9

santoshtiwari
Автор

Sir why are you repeating java basic lecture because there are basic java videos in your channel...?

satyam
Автор

Why ternary operator is written as a comment?

rehankhaled
Автор

Can u plz make a video on *Iteration through loops*
M in std 9.

grasstoucher