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



Download 3,91 Mb.
Pdf ko'rish
bet55/70
Sana02.04.2022
Hajmi3,91 Mb.
#524999
1   ...   51   52   53   54   55   56   57   58   ...   70
Bog'liq
Java for Fucking Idiots

"we live in a society"
.charAt(
1
);
This returns the 
‘e’
character.
"I hate sand"
.charAt(
7
);
This returns the 
‘s’
character.
Yes, spaces from your spacebar 
“ “
are characters, so you need to include
them when you’re dealing with the indexes of characters in a String.
Not too bad. Now for the next method. :)
substring
Let’s say we want to get the first 5 letters of a String.
String helloWorld =
"Hello, world!"
;
Oh god, it’s back.
Anyway, we can pull out a “substring” inside this String by giving Java the
starting index and ending index of the characters we want.
String firstFive = helloWorld.substring(
0
,
5
);
This is saying “get me the 0
th
character up to the 5
th
character”. The result of
which is “Hello”.
Wait, 0 to 5? Isn’t that 6 characters? 0, 1, 2, 3, 4, 5….that is 6! What the hell
is happening here?! Why did we only get “Hello” and not the comma too?
Here’s the tricky bit (you knew it was coming): Java don’t work like that.
You are asking to get the 0
th
character UP TO, NOT INCLUDING the 5
th
character. This is known as “inclusive” and “exclusive”.
String firstFive = helloWorld.substring(
0
,
5
);
“Get the substring starting at index 0 INCLUSIVE and ending at index 5
EXCLUSIVE.”


0, 1, 2, 3, 4, 5 (here, 5 is the friend without a group in class and is left out) 
H, E, L, L, O
Let’s do another.
Look who’s purging now
"Ah geez I don’t know Rick"
.substring(
4
,
7
);
Let’s say this String is written out on a thin sheet of paper.
Picture taking some scissors and cutting the string at position 4 and 7.
Everything we don’t want is thrown into the wastepaper bin.
Cut one
The first cut we make is at the lowercase g in “geez”. It’s 4 over from the
left.
Because the rules state that we include the first index in our result, we cut to
its left so we don’t lose it. “Ah “ is then thrown in the trash.
Cut two
The second cut we make is at the blank space “ “ after “I”. It’s 7 over from
the left.
Remember; we don’t want the character at the 7
th
index; it’s excluded . We
also don’t want anything to the right of it.
Because the rules state that we exclude the last index in our result, we cut to
its left so it’s excluded. Everything to the right of, and including the blank
space “ ” is then thrown out.
Snipping complete! The paper remaining says “geez”.
In the trash, we have 
“Ah “
and 
“ I don’t know Rick”
. Visualize the String
being cut up and follow these instructions once or twice again.
More sugar
I know. I know. You’re an idiot newbie and you’re still confused. But this is
one of those things that really just needs drilled into your head.
Here, I’ll give you some examples to help you out, friend. Use your finger
to count from left to right and make sense of why the results are what they


are:
//"NOP"

Download 3,91 Mb.

Do'stlaringiz bilan baham:
1   ...   51   52   53   54   55   56   57   58   ...   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