— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet41/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   37   38   39   40   41   42   43   44   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

4
5
OK, so the beer song wasn’t really a serious 
business application. Still need something 
practical to show the boss? Check out the 
Phrase-O-Matic code. 
note: when you type this into an editor, let 
the code do its own word/line-wrapping! 
Never hit the return key when you’re typing 
a String (a thing between “quotes”) or it 
won’t compile. So the hyphens you see on 
this page are real, and you can type them, 
but don’t hit the return key until AFTER 
you’ve closed a String.


you are here
4
dive In 
A Quick Dip
17
Phrase-O-Matic
How it works.
In a nutshell, the program makes three lists of words, then randomly picks one word 
from each of the three lists, and prints out the result. Don’t worry if you don’t under-
stand exactly what’s happening in each line. For gosh sakes, you’ve got the whole book 
ahead of you, so relax. This is just a quick look from a 30,000 foot outside-the-box 
targeted leveraged paradigm.
1.
The first step is to create three String arrays – the containers that will hold all the 
words. Declaring and creating an array is easy; here’s a small one:
String[] pets = {“Fido”, “Zeus”, “Bin”};
Each word is in quotes (as all good Strings must be) and separated by commas.
2.
For each of the three lists (arrays), the goal is to pick a random word, so we have 
to know how many words are in each list. If there are 14 words in a list, then we need 
a random number between 0 and 13 (Java arrays are zero-based, so the first word is at 
position 0, the second word position 1, and the last word is position 13 in a 14-element 
array). Quite handily, a Java array is more than happy to tell you its length. You just 
have to ask. In the pets array, we’d say:

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   37   38   39   40   41   42   43   44   ...   555




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