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


char [] userFavoriteLetters = new char



Download 3,91 Mb.
Pdf ko'rish
bet28/70
Sana02.04.2022
Hajmi3,91 Mb.
#524999
1   ...   24   25   26   27   28   29   30   31   ...   70
Bog'liq
Java for Fucking Idiots

char
[] userFavoriteLetters =
new char
[
10
];
userFavoriteLetters[
1
] =
'Q'
;
See what I did there? I said “Put the letter Q in the first slot.”
And you can keep doing this shit:
userFavoriteLetters[
2
] =
'C'
;
Hell, you can even jump right to this:
userFavoriteLetters[
7
] =
'Z'
;
Your array, under the hood, looks like this now:
[ , Q, C, , , , , Z, , ]
So we put the user’s favorite letter, Q, in the first slot, then we put….wait.
Hold the phone.
Is that a comma before the Q? Is Q not in the first slot? The first slot
appears to be empty! WHAT’S HAPPENING?!
I’ll tell you: arrays start at 0 in Java . That’s right, slot 0 is the first
position, not slot 1. The correct way to put something in the first slot is:
userFavoriteLetters[
0
] =
'Q'
;
This is
incredibly 
important! Arrays are used all throughout
Java, even if you’re not aware of it at times. And by the way, it’s not just
papa Java coming up with some weird “start at 0” rule, nearly every
programming language does this.


So yes, once your array is created, you can put things into it with some
square brackets 
[]
.
I’ll show a few more examples for your benefit.
String[] words = {
"Hello"
,
"world"
};
This is an array of length 2 because there are 2 things in there.

Hello
” is at position 0 and “
world
” is at position 1.
words[
1
] =
"universe"
;
Now, “
Hello
” is at position 0, but “
universe
” is at position 1.
Getting shit from the box
Pretty much the same way you put things in, with some square brackets [].

Download 3,91 Mb.

Do'stlaringiz bilan baham:
1   ...   24   25   26   27   28   29   30   31   ...   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