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


if (numGiraffes > 500 ) { System. out



Download 3,91 Mb.
Pdf ko'rish
bet20/70
Sana02.04.2022
Hajmi3,91 Mb.
#524999
1   ...   16   17   18   19   20   21   22   23   ...   70
Bog'liq
Java for Fucking Idiots

if
(numGiraffes >
500
) {
System.
out
.println(
"Please send help."
);
}
That line of code that prints to the system only happens if we have more
than 500 giraffes.
Another example:
Scanner userInputReader =
new
Scanner(System.
in
);
int
userInputNumGiraffes = userInputReader.nextInt();
if
(userInputNumGiraffes <=
0
) {
System.
out
.println(
"Where they at?"
);
}
That line of code prints to the system only if the user typed in a 0. Or a
negative number. I’m going to skip explaining how to 
get input via a
Scanner
 , OK? Really, really dull stuff.
Anyway, does the 
if
part make sense? It’s pretty similar to English, really. 
If
this, do that.


Now, what if we also want to do something when the user types in an actual
value? If you remember the comparison operators, you could add something
like this below that conditional:
if
(userInputNumGiraffes <=
0
) {
System.
out
.println(
"Where they at?"
);
}
if
(userInputNumGiraffes >
0
) {
System.
out
.println(
"I shall add them at once."
);
}
Two 
if
statements, back-to-back. Could work, right? But that’s stupid. Why
check the value of 
userInputNumGiraffes
in two places? Don’t do that.
Instead, add an else block to the original 
if
statement, as follows:
if
(userInputNumGiraffes <=
0
) {
System.

Download 3,91 Mb.

Do'stlaringiz bilan baham:
1   ...   16   17   18   19   20   21   22   23   ...   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