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



Download 3,91 Mb.
Pdf ko'rish
bet47/70
Sana02.04.2022
Hajmi3,91 Mb.
#524999
1   ...   43   44   45   46   47   48   49   50   ...   70
Bog'liq
Java for Fucking Idiots

new
Translator(
"English"
,
"Spanish"
);
Right now we have him wired up to go from English to Spanish.
We can call the translate method to learn how we find a bathroom in
Spanish.
eugene.translate(
"Where is the bathroom?"
);
We did it. Right? I think we did. But where’s the Spanish translation? Did
Eugene translate it in his head but not even tell us the translation?
EUGENE? WHAT’S THE TRANSLATION? HELLO? USE YOUR
WORDS.


The problem is our translate method is void .
void methods do not give us any data when they’re done executing. They do
something, and that’s it. It’s like sending a text message and hearing
nothing back, no matter how hard you wish they’d just fucking reply.
Eugene translated it in his head but didn’t share with us. We can fix this by
making his method return a String.
String
translate(String textToTranslate) {
textToTranslate = textToTranslate.trim();
String translation =
//write this code later

return
translation;
}
This special keyword 
return
ends the method right there; no code can exist
after a return; statement. Method’s over, result is returned. 
Methods can 
return
any of the data types we’ve seen, whether primitive
variables like int, char, boolean, or objects like String, Cat, or Meme.
In this case, we replaced 
void
with 
String
. Now we can learn the translation
from Eugene without having to fire him.
Translator eugene =
new
Translator(
"English"
,
"Spanish"
);
String translatedString = eugene.translate(
"Where is the bathroom?"
);
System.
out
.println(translatedString);
> “¿Dónde está el baño?”
Thanks, Eugene!!
Conditional returns!
“What is this, a crossover episode?” – Mr. Peanutbutter
In this little section, conditionals return. Hah. They return. Literally. Cause
they’re back and….alright.
Anywho, you can actually have multiple return statements in your methods.
The rule is that nothing can exist in a method after a return statement; but


what if your return statement is inside a conditional? You’ll need multiple
return statements then!
For non-void methods, Java needs an absolute 100% guarantee that the
method will return a value. This would be unacceptable:

Download 3,91 Mb.

Do'stlaringiz bilan baham:
1   ...   43   44   45   46   47   48   49   50   ...   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