#15 Switch Statement in Java

  Рет қаралды 118,094

Telusko

Telusko

Жыл бұрын

Check out our courses:
Spring and Microservices Weekend Live Batch : bit.ly/spring-live-weekend
Coupon: TELUSKO10 (10% Discount)
Master Java Spring Development : bit.ly/java-spring-cloud
Udemy Courses:
Java:- bit.ly/JavaUdemyTelusko
Spring:- bit.ly/SpringUdemyTelusko
Java For Programmers:- bit.ly/javaProgrammers
For More Queries WhatsApp or Call on : +919008963671
website : courses.telusko.com/
In this lecture we are discussing:
1) What is switch statement?
2) why we need switch statement?
3) What datatype can we use in switch?
4) Syntax of switch and example
5) Need of break
6) Need of default
#1
-- switch statement is a multiway branch statement that allows a variable to be tested for equality against a list of values
each value is called a case, and the variable being switched on is checked for each switch case.
#2
if we have multiple test cases and we want to test for a particular value then we can use switch statement.
At the place switch we can also use if-else-if ladder.
e.g
suppose user enter a your date of birth and we want to check from multiple year then
in this case we can use switch case.
#3
what dataType we can use in switch statement?
-- the switch statement can have a number of possible execution paths. A switch works with the
byte, short, char, and int primitive data types. It also works with enumerated types (discussed in Enum Types),
the String class, and a few special classes that wrap certain primitive types: Character, Byte, Short, and Integer.
#4
Syntax of Switch and example:
switch(variable){
case x1:
//code
break;
case x2:
//code
break;
default:
//code
}
example:
int x=9;
switch(x){
case 8:
System.out.println("8");
break;
case 7:
System.out.println("7");
break;
default:
System.out.println("No match found");
}
#5
Need of break
-- The break statements are necessary because without them, statements
in switch blocks fall through: All statements after the matching case label
are executed in sequence, regardless of the expression of subsequent case labels,
until a break statement is encountered. The program shows
statements in a switch block that fall through.
int x=5;
switch(x){
case 5:
System.out.println("five");
case 4:
System.out.println("six);
default:
System.out.println("default");
}
output:
five
six
default
Since, we are not using break after matching the case 5
it execute all remaining statements without check.
#6
Need of default:
The default section handles all values that are not explicitly handled by one of the case sections.
example:
int y=9;
switch(y){
case 8:
System.out.println("8");
break;
case 7:
System.out.println("7");
break;
}
In this case you don’t get any result because no case is match and
since no default case is available so, nothing we get.
Github repo : github.com/navinreddy20/Javac...
Java:- bit.ly/JavaUdemyTelusko
Spring:- bit.ly/SpringUdemyTelusko
More Learning :
Java :- bit.ly/3x6rr0N
Python :- bit.ly/3GRc7JX
Django :- bit.ly/3MmoJK6
JavaScript :- bit.ly/3tiAlHo
Node JS :- bit.ly/3GT4liq
Rest Api :-bit.ly/3MjhZwt
Servlet :- bit.ly/3Q7eA7k
Spring Framework :- bit.ly/3xi7buh
Design Patterns in Java :- bit.ly/3MocXiq
Docker :- bit.ly/3xjWzLA
Blockchain Tutorial :- bit.ly/3NSbOkc
Corda Tutorial:- bit.ly/3thbUKa
Hyperledger Fabric :- bit.ly/38RZCRB
NoSQL Tutorial :- bit.ly/3aJpRuc
Mysql Tutorial :- bit.ly/3thpr4L
Data Structures using Java :- bit.ly/3MuJa7S
Git Tutorial :- bit.ly/3NXyCPu
Donation:
PayPal Id : navinreddy20
www.telusko.com

Пікірлер: 19
@egehanisk2512
@egehanisk2512 Жыл бұрын
Thank you sir you are a really good teacher. As a Computer Engineering studunt your videos is really good for preapring for my programing classes.
@zacharybrown7869
@zacharybrown7869 9 ай бұрын
Wow now it all makes sense! Thanks!
@user-ew2tj6oi2y
@user-ew2tj6oi2y 9 ай бұрын
sir ur explanation is so good,i like python but when i saw ur videos i am liking java aganist to python...thank u sir
@gregsonmwavuna2702
@gregsonmwavuna2702 6 ай бұрын
Superb explanation on tenary operators
@datareport1582
@datareport1582 Жыл бұрын
Good video
@prasadkota77
@prasadkota77 7 ай бұрын
Tq sir
@user-ne5fq5rw2h
@user-ne5fq5rw2h Жыл бұрын
Sir for what purpose we are giving (x:) in printing Statement
@durgaraoponnuru17
@durgaraoponnuru17 Жыл бұрын
It's dummy variable that's automatically generated by extension added .
@davidking4849
@davidking4849 17 күн бұрын
That is the extension in his IDE software
@botaccount9376
@botaccount9376 3 ай бұрын
Sir does the n value check with the case value to give output ?
@vanshjaiswal7588
@vanshjaiswal7588 Жыл бұрын
Sir in which video we will learn how to take input
@Alfredo5883
@Alfredo5883 4 ай бұрын
Lookup "Scanner"
@shinjini202
@shinjini202 3 ай бұрын
Scanner class
@Anshul_.621
@Anshul_.621 11 ай бұрын
are DSA taught in this playlist
@AnuragRawat01
@AnuragRawat01 11 ай бұрын
I dont think so It's Java playlist
@teshomebirhanu4141
@teshomebirhanu4141 9 ай бұрын
how can we handle multiple variables by switch statement?
@shubhamsingh1316
@shubhamsingh1316 7 ай бұрын
Switch statement don't accept multiple variables. It accepts only one value at a time
@Ibrahimmhardi-ig7nq
@Ibrahimmhardi-ig7nq 4 ай бұрын
What if I want to prompt a user to enter the number
@yasaswanilovely1807
@yasaswanilovely1807 3 ай бұрын
You can use scanner class, which takes input during run time.
What's new in Java Switch | Switch Statement and Expression
11:09
#22 Class and Object Practical in Java
15:36
Telusko
Рет қаралды 200 М.
路飞被小孩吓到了#海贼王#路飞
00:41
路飞与唐舞桐
Рет қаралды 67 МЛН
The child was abused by the clown#Short #Officer Rabbit #angel
00:55
兔子警官
Рет қаралды 25 МЛН
Vivaan  Tanya once again pranked Papa 🤣😇🤣
00:10
seema lamba
Рет қаралды 34 МЛН
#12 If else in Java
12:59
Telusko
Рет қаралды 122 М.
#6 Data types in Java
12:19
Telusko
Рет қаралды 242 М.
Switch Statement in Java (Hindi) | Learn Coding
14:57
Learn Coding
Рет қаралды 139 М.
#3 First Code in Java
11:17
Telusko
Рет қаралды 414 М.
Switch Statements + Nested Case in Java
26:11
Kunal Kushwaha
Рет қаралды 307 М.
#48 What is Inheritance in Java
8:47
Telusko
Рет қаралды 108 М.
#9 Arithmetic Operators in Java
10:16
Telusko
Рет қаралды 151 М.
تجربة أغرب توصيلة شحن ضد القطع تماما
0:56
صدام العزي
Рет қаралды 36 МЛН
Samsung Galaxy 🔥 #shorts  #trending #youtubeshorts  #shortvideo ujjawal4u
0:10
Ujjawal4u. 120k Views . 4 hours ago
Рет қаралды 3,8 МЛН
Опять съемные крышки в смартфонах? #cmf
0:50
НЕ ПОКУПАЙ СМАРТФОН, ПОКА НЕ УЗНАЕШЬ ЭТО! Не ошибись с выбором…
15:23
WATERPROOF RATED IP-69🌧️#oppo #oppof27pro#oppoindia
0:10
Fivestar Mobile
Рет қаралды 17 МЛН