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


When an array is created, Java must know the exact size it is and always



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

When an array is created, Java must know the exact size it is and always
will be.
In the previous examples where we gave the array all its values when it was
created, Java knew the size, right? Remember this guy?
int
[] favoriteNumbers = {
6

9

420
};


We told Java right off the bat there’s 3 things in this array, and here they
are.
But when we can’t give all the values at the beginning, then Java at least
needs to know the size!
That’s what the 
10
says; there will be 
10
things, or “elements” in this array.
The “new” part is saying you’re making a new array, and is just a required
word by Java.
We’ll get more into what new actually means later, but DON’T WORRY
ABOUT IT OKAY? CALM DOWN. REMAIN CALM.
Just know that with this line of code, we create a box with 10 empty slots in
it. Rejoice, and let’s keep going:
char
[] userFavoriteLetters =
new char
[
10
];
OH, one more thing. Very important.
You can tell how big your Array is using a very special “property” on the
array object, length . Remember properties? Variables that describe an
object? Well, arrays are objects so they can have properties, too.
For the 
userFavoriteLetters
array, what would the length be? Well, it would
be 
10
. Try it.
System.
out
.println(userFavoriteLetters.
length
);
It prints out 10. Very useful for later when we do loops, keep this in mind!
Putting shit in the box
“Well, the square brackets start comin’ and they don’t stop comin’ and they
don’t stop comin’…” – Smash Mouth
So, we’ve got an array with 10 slots. How do we put something in those
slots? No, that’s not a dirty innuendo.


The answer is… we use the assignment operator (that’s the equals sign)
combined with square brackets to specify which slot in the box will be
assigned a value.
Check this out:

Download 3,91 Mb.

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