- 1
What is switch I am not understand it മലയാളികളുണ്ടെങ്കിൽ മലയാളത്തിലൊന്ന് പറഞ്ഞ് തരണേ
what is switch in java and what is it's use
3 Answers
+ 4
switch(condition){
case(possible match){execute code}
case(possible match){execute code}
default{code run if no match}
}
+ 2
A switch statement is a replacement for writing multiple if-else statements.
So if you want to run different code blocks depending on the day of the week you would use a switch.
switch (day){
case 1{
println ("Today is Sunday")
}
case 2{
println ("Today is Monday")
}
case 3{
println ("Today is Tuesday")
}
case 4{
println ("Today is Wednesday")
}
case 5{
println ("Today is Thursday")
}
case 6{
println ("Today is Friday")
}
case 7{
println ("Today is Saturday")
}
}
So if the variable day=5 the program would print Thursday to the screen.
0
Thanks