Learn Java Tutorial for Beginners, Part 9: Switch

preview_player
Показать описание
-------------------------------------------------------------------------------------------------------------------------------------------
How to use the switch statement in Java.
--------------------------------------------------------------------------------------------------------------------------------------------
Рекомендации по теме
Комментарии
Автор

I'm so thankful for your thorough and very helpful tutorials! Thanks, John!!

tjames
Автор

Man, you could easily get job at making audiobook bedtime stories for kids. Your voice is so soothing.

medotata
Автор

Use toLowerCase() on the string your user enters, then compare the lowercase string with "start" in the switch.

caveofprogramming
Автор

Yes, you can do the following. By the way, programming games is an excellent way to learn programming. That's how I started; I got a job as a developer a year later (sadly not programming games though!!)

String text = "Hello how are you?";

if(text.contains("how")) {
System.out.println("found it.");
}

caveofprogramming
Автор

Thanks so much! This is a HUGE help to me

hairypotty
Автор

So an easy way to get the machine to keep going is to put the sysout and the switch into a do while loop, and the condition is
while(input != stop);

Please correct me if I’m wrong

nutmeggaming
Автор

I was wondering about that. Wasn't aware it had changed in Java 7.

tabularasa
Автор

hello John can you code simple English to English dictionary in Java please just to give me a hint...

abdulahad
Автор

I need help on this corse it was going smooth until I typed in text after switch I added the swigly line but (text) just come up incorrect and I looked at yours and at mine and their exancly the same ecept my text is red it says "can't switch value of type string for source level below 1.7. Only convertible int values or enum variables are permitted." Help please

Chris-jegl
Автор

don't you need 'break' at the end of default?

adriangamrot
Автор

Is there a way to only recognize certain words, not the whole string?
Let's say I'm making a text-based game.
If you say "Go to the north, " it would look for the word "north" and execute a command.
Thanks in advance!

hairypotty
Автор

I know that doing a switch statement with String is new. That it used to be reserved only for int, char and double. However, I have heard that if the user has an old version of Java installed on their computer the String switch statement will make your program crash. That better just to be safe and not use String switch statements. Any advice on this issue?

anljdfvcwafd
Автор

if some one type "Start" than the default case will be execute but want to know how to solve this type of lower or upper case problem on switch statement. thanks in advance

vangarecord
Автор

Somehow I downloaded an old version of Eclipse, and it was pointing to Java 1.6, which won't allow switching on String types. So I have the newest version (Juno) now, that fixed it. Here's the error: "Cannot switch on a value of type String. Only int values or enum constants are permitted."

unclvinny
Автор

Is there something wrong with the videos? I'm experiencing some problems on my 📱 while other YouTube videos work just fine

puneetbhandarkar
Автор

Hello friend which software do you use to write the program

namirkhan
Автор

Thanks for the great tutorials:)Actually I've run the exact code that you wrote but got an error: " Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum variables are permitted " . Is that due to an old version of eclipse?should I upgrade it?

sinanfr