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



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

switch
(keyPressed) {
case
'W'
:
player.moveForward();
break
;
case
'A'
:
player.moveLeft();
break
;
case
'S'
:
player.moveBackward();
break
;
case
'D'
:
player.moveRight();
break
;
default
:
player.stopMoving();
break
;
}
Now when one of the cases is matched, Java will hit the kill switch (hehe)
when it sees 
break
and prevent anything else in the switch statement from
running. Java jumps down to any code below the entire switch statement
(outside the curly braces {} )
Why do we need to do this?
“Because fuck you, that’s why.” - Java
Now tell me, which is easier to understand, some if/else ’s, or a
switch/case/break/default cluster? It’s totally your choice. Want to do
something different based upon a certain variable’s value? Pick the one you
like better.
But if you choose a switch you’d better hope you don’t forget your break
statements (and it does happen).


CHAPTER 7: ARRAYS
 
“Isn’t there anything on TV that isn’t about BOXES?!?!
We now return to Championship boxing.” – Spongebob Squarepants
Pop quiz: What’s the first letter of the alphabet?
Answer: (doo doo, doo doo, doo doo) The Daily Double
Okay, no. It’s actually A .
How would we represent that letter in Java? Which data type?
Tick.
Tock.
Tick.
Tock.
Did you guess a char ? If so you’re right! If not… shucks! I was really
rooting for you, dumbo. Here it is!
char
firstLetter =
'A'
;
Congratulations again.
More than one value??
Cool. Now, what if I asked you, “what are the letters of the alphabet?”
You’d probably start singing the song: “A B C D E F G, H I J K
LMNOP…”


So, how would we represent that in Java? What kind of variable can
represent the entire alphabet?
The answer… is… an array ! Did you get it? If you did, WAT? HOW? I
haven’t talked about arrays yet. You’re a goddamn cheater.
Anyway, Java has this idea of an “array,” which is pretty much a box of
variables. Watch, I’ll spell it out for you (literally, if you read aloud! Hah!
Ahaha! Ahem…)
char
[] alphabet;
Look at that! Those square brackets [] are saying that the variable 
alphabet
is an array (or box) of characters. Meaning it can be more than one letter.
Absolutely mesmerizing. Thanks Java!
should mention that you could also put the square brackets to the right of
the variable name…
char
alphabet[];
But no one does that anymore and neither should you if you wanna be cool.
Filling the box in one go
But let’s keep going. How do we put things inside the box? Well, let’s
initialize that variable that we just declared.
alphabet = {

Download 3,91 Mb.

Do'stlaringiz bilan baham:
1   ...   21   22   23   24   25   26   27   28   ...   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