Java switch ⬇【4 minutes】
HTML-код
- Опубликовано: 18 окт 2020
- Java switch statement
#Java #switch #statement
public class Main {
public static void main(String[] args) {
// switch = statement that allows a variable to be tested for equality against a list of values
String day = "Friday";
switch(day) {
case "Sunday": System.out.println("It is Sunday!");
break;
case "Monday": System.out.println("It is Monday!");
break;
case "Tuesday": System.out.println("It is Tuesday!");
break;
case "Wednesday": System.out.println("It is Wednesday!");
break;
case "Thursday": System.out.println("It is Thursday!");
break;
case "Friday": System.out.println("It is Friday!");
break;
case "Saturday": System.out.println("It is Saturday!");
break;
default: System.out.println("That is not a day!");
}
}
} - Наука
public class Main {
public static void main(String[] args) {
// switch = statement that allows a variable to be tested for equality against a list of values
String day = "Friday";
switch(day) {
case "Sunday": System.out.println("It is Sunday!");
break;
case "Monday": System.out.println("It is Monday!");
break;
case "Tuesday": System.out.println("It is Tuesday!");
break;
case "Wednesday": System.out.println("It is Wednesday!");
break;
case "Thursday": System.out.println("It is Thursday!");
break;
case "Friday": System.out.println("It is Friday!");
break;
case "Saturday": System.out.println("It is Saturday!");
break;
default: System.out.println("That is not a day!");
}
}
}
Thank you for always taking the time to put the code in the comments.
@@_Anna_Nass_ he can easily copy and paste lol
@@_Anna_Nass_ because he is smart and helpful
You can write "->" instead of ":" and you don't need now writing break at the end
switch(day) {
case "Sunday" -> System.out.println("It is Sunday!");
case "Monday" -> System.out.println("It is Monday!");
or
switch(day) {
case "Sunday" -> {
System.out.println("It is Sunday!")
System.out.println("It's a free day!")
};
case "Monday" -> {
System.out.println("It is Monday!")
System.out.println("It's not a free day!")
};
}
if you need to run more than 1 command.
Sout enter and only bro code
System.out.println("Awesome explanation!") ;
No main method found in program
public class Human
{
public static void main(String args[])
{
System.out.println("Awesome Explanation!" );
}
}
@@Sqrt.Infinity incorrect indentation
This is the best Java tutorial for beginners, so you can learn Java and English in one hit. Please keep going! I vote for Java advance tutorial. Thanks a lot Bro
quick reminder.
Now you can use lambda expression:
switch(number) {
1 -> do something;
2 -> do something;
3 -> do something
}
instead of
switch(number) {
case 1: do something;
break;
case 2: do something;
break;
case 3: do something
break;
}
what will be the default and break for this expression
Learning the beginnings of Java in school but the tricks in these tutorials are awesome like: sysout + strg/ctrl + space
An exciting and brief course by bro absolutely amazing may your channel grow big Af
your tutorials are always amazing thanks bro
You teaches the peaches, for real. Thank you so much for taking the time to create these lessons. You've designed them in such a order, that while I'm learning I can take a new concept that you're teaching me, and apply it with one of your previous lessons easily. Right now I'm creating switch statements while interfacing a GUI. I wish you would have squeezed a video about using getText() though, because Scanner can't be used with JOptionPane apparently x). Thank you for teaching me stuff and things, Proffeser Bro.
(◍•ᴗ•◍)✧*。(◍•ᴗ•◍)✧*。(◍•ᴗ•◍)✧*。(◍•ᴗ•◍)✧*。(◍•ᴗ•◍)✧*。(◍•ᴗ•◍)✧*。(◍•ᴗ•◍)✧*。(◍•ᴗ•◍)✧*。(◍•ᴗ•◍)✧*。(◍•ᴗ•◍)✧*。(◍•ᴗ•◍)✧*。(◍•ᴗ•◍)✧*。(◍•ᴗ•◍)✧*。(๑˙❥˙๑(ʃƪ^3^)(◍•ᴗ•◍)✧*。(◍•ᴗ•◍)✧*。(◍•ᴗ•◍)✧*。(◍•ᴗ•◍)✧*。(◍•ᴗ•◍)✧*。(◍•ᴗ•◍)✧*。(◍•ᴗ•◍)✧*。(๑˙❥˙๑)(◍•ᴗ•◍)✧*。(◍•ᴗ•◍)✧*。(◍•ᴗ•◍)✧*。(◍•ᴗ•◍)✧*。(◍•ᴗ•◍)✧*。(◍•ᴗ•◍)✧*。(◍•ᴗ•◍)✧*。(◍•ᴗ•◍)✧*。(◍•ᴗ•◍)✧*。(◍•ᴗ•◍)✧*。(◍•ᴗ•◍)✧*。(๑˙❥˙๑)(◍•ᴗ•◍)✧*。(◍•ᴗ•◍)✧*。(◍•ᴗ•◍)✧*。(◍•ᴗ•◍)✧*。(◍•ᴗ•◍)✧*。
Really love your videos.I need to support you!!!!
bro, thank you for everything, you helped me pass my ict subject and make coding fun!
im going to like all your videos. you are saving me. thx bro !!!
Thank you so much. Well explained
Your the best Java Teacher on youtube.
Love ur videos bro :>
You teached me alot sir, Thank you!
I always come back to this channel to learn anything
Well explained!
This is really lit bruh🔥🔥
Tomorrow i've got a Java exam in school, and this helped a lot. Thanks
Thank you, Bro Sensei👍
Maaaan you got 170 likes and 0 dislikes this is the proof that you are really really really good i think even a monkey would understand java with your lessons you are too good at explaining it
lol fr
Great video!
Thank you again 💙💙
I don't know what i have to comment, just wanna comment to support this channel tho
Thanks man
very much appreciate it
Thanks for the video
good video bro!
you are a hero bro
Thank you🙌
you are amazing!
Thank you bro
I’ve been learning Java programming on my end for almost 1 month now, and all of the theoretical concepts and logic understanding is only on top of my head, I’ve got a MacBook, so I’m wondering if you have a recommendation about a program for coding to start with, I’d appreciate it since I tried but they did not work properly (
the good thing in the switch tag is that we can put another condition inside of it.
thank you!
well explained
Easy! Thank you
I love you chanel !!!
@Bro code While making a simple rock paper scissor program I had a recommendation for a rule switch in netbeans. What is a rule switch how and when should it be used?
Thanks for your explanation Bro ! May I know why it shows default whenever I type Monday with small letter m. how can i solve to show correctly without caring Monday or monday
For the default statement you should have said "That is not a day, but it should be :))."
thank u so much
THANK YOU homie. My ass had no idea what this was in class today. Saved my ass 30 minutes to rewatching lecture videos lol. I think my professor sucks.
BRO code !!! You are the chosen one, to be the None Indian RUclips Teacher :))
How do I do it if I want to pick a random variable in the switch statement?
Teachers seeing this and making it 2 hours long:
you are the best.
Ty bro
Ily so much
Thanks bro
thank you brother you saved my day🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰🥰😍😍😍😍😌😌😌😌
thx 4 vid bro
Thank you bro code!
ty bro
Thanku Bro🙏🙏🙏🙏
Thanks
i wonder if python has a similar way for handling multiple conditions
Can we apply switch case to integer also ?
thanks
Switching case the next lesson, default is learning
I like your teaching style. hhhh
good video
thanks brah
THank!
Thanx bro
Thanks Bro code ❤
thankyou Bro
❤❤❤❤❤ great 🎉🎉🎉🎉
legend
Yeah I become a hero !!
Nice.
nice
thx
cool!
good to know
So can you add 3 together like
Sunday , Monday and Tuesday
Instead of putting too many break ;
God Bless you Bro +7
doing my part for the algorithm
doing well!
Like it
merci
thx learnt
What if i type "monday" instead of "Monday".
How can I ignore the case?
Btw thank u bro I love ur videos. Keep it up!
I did the way you taught. But when I run the program it says "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum variables are permitted" whats wrong?
Me too, can you help me?
Look what you have to do
Right click on your project, go to Properties. Select Java Compiler from the left menu. Select your compliance level (1.7 or 1.6). 1.7 will stop that message. 1.6, as others said before, won't let you use strings
thank you @@mouradjaafar6013
i though you need to give number for each case
Thanks, bro. Algorithm comment
just switchted to the switch video
nOt FuNnY lOl
❤❤❤
dropped a comment
could you make it so that it randomly generates a day from a list so that it says a random statement instead of you manually changing it?
of course you can!
@levimonarca did you create an array list and add all of the values into that? Sorry I’m just trying to understand
Hiw?
How?
Bro#1
If I become president, I will make pizza the 8th day of the week.
❤🔥
❤
pro gunga moment here
❤️👌
4 february done
Thanks Bro!
i dunno if i'll switch to eclipse after 2 years of netbeans
update did you switch?
pizza is not a day indeed
my comment bro thank you bro