Java for Fucking Idiots: Learn the Basics of Java Programming Without any experience!



Download 3,91 Mb.
Pdf ko'rish
bet23/70
Sana02.04.2022
Hajmi3,91 Mb.
#524999
1   ...   19   20   21   22   23   24   25   26   ...   70
Bog'liq
Java for Fucking Idiots

if
(userInputNumGiraffes < 
0
) { 
System.
out
.println(
"Get your hands the fuck off my giraffes."
); 

else if
(userInputNumGiraffes == 
0
) { 
System.
out
.println(
"Sorry, you can cannot add 0 giraffes to the zoo."
); 

else if
(userInputNumGiraffes < 
3
) { 
System.
out
.println(
"Thanks for donating 1-2 giraffes."
); 

else if
(userInputNumGiraffes < 
10
) { 
System.
out
.println(
"Thanks for donating 3-9 giraffes."
); 

else

System.
out
.println(
"How did you have 10+ giraffes?"
); 
}
Doesn’t that look better than your nested if/else statements stretching out to
the right, riding off into the sunset?
The ‘switch’ statement
Let’s change up the example, because while I love long-necked creatures
that primarily exist to feed lions, I could benefit from a change of imagery.
We’re creating a video game. The user presses a button on their keyboard.


If they pressed W, move the player forward.
Else if they pressed A, move the player left.
Else if they pressed S, move the player backward.
Else if they pressed D, move the player right.
Else if….
See? It’s like a multiple-choice test!
While we could continue this pattern of doing if/else if, else if, else if, else
if checks until our heart dies out, there’s an easier way; the switch
statement.
Well, maybe not easier. I personally find it a bit overrated and think it opens
you up to making mistakes but screw it, you should know it.
I’ll show you both. The way we’d do it with what we know so far: 

Download 3,91 Mb.

Do'stlaringiz bilan baham:
1   ...   19   20   21   22   23   24   25   26   ...   70




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish