#3.2 Java Tutorial | Ternary and Switch | Selection Statement

Описание к видео #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:
System.out.println("Two");
break;
case 5:
System.out.println("five");
break;
default:
System.out.println("not matched");
}

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":
System.out.println("shiva");
break;
case "harsh":
System.out.println("shiva");
break;
case "muskan":
System.out.println("shiva");
break;
default:
System.out.println("default");
break;
}

Note: in further lecture we discussed how modern switch works.




Instagram :   / navinreddyofficial  
Linkedin :   / navinreddy20  
Discord :   / discord  

More Learning :

Java - https://bit.ly/3xleOA2
Python :- https://bit.ly/3H0DYHx
Django :- https://bit.ly/3awMaD8
Spring Boot :- https://bit.ly/3aucCgB
Spring Framework :- https://bit.ly/3GRfxwe

Servlet & JSP :- https://bit.ly/3mh5CGz
Hibernate Tutorial :- https://bit.ly/3NWAKah
Rest API | Web Service Tutorial :- https://bit.ly/38RJCiy

Git :- https://bit.ly/3NUHB3V
JavaScript :- https://bit.ly/3mkcFys
Kotlin :- https://bit.ly/3GR2DOG

Donation:
PayPal Id : navinreddy20
Patreon : navinreddy20
http://www.telusko.com/contactus

Комментарии

Информация по комментариям в разработке