Head First Java a brain-Friendly Guide Kathy Sierra and Bert Bates


Puzzle4b [ ] obs = new Puzzle4b[6]



Download 17,18 Mb.
Pdf ko'rish
bet70/90
Sana22.06.2022
Hajmi17,18 Mb.
#693704
1   ...   66   67   68   69   70   71   72   73   ...   90
Bog'liq
(Head Up) Kathy Sierra Bert Bates - Head First Java, 3rd Edition Early Release-O\'Reilly Media, Inc. (2021)

Puzzle4b [ ] obs = new Puzzle4b[6];
int y = 1; 
int x = 0; 
int result = 0; 
while (x < 6) { 
obs[x] = new Puzzle4b( );
obs[x] . ivar = y;
y = y * 10; 
x = x + 1;

x = 6; 
while (x > 0) { 
x = x - 1;
result = result + 
obs[x].doStuff(x);



System.out.println(“result “ + result); 


class 
Puzzle4b

int ivar; 
public int
doStuff(int 
factor
) { 
if (ivar > 100) { 
return 
ivar * factor;
} else { 
return 
ivar * (5 - factor);


}
Output
Answer to the 5-minute mystery...
Jai knew that Buchanan wasn’t the sharpest pencil in the box. When Jai
heard Buchanan talk about his code, Buchanan never mentioned his
instance variables. Jai suspected that while Buchanan did in fact handle his
methods correctly, he failed to mark his instance variables 
private
. That
slip up could have easily cost Leveler thousands.



Chapter 5. Writing a Program:
Extra-Strength Methods
Let’s put some muscle in our methods.
We dabbled with variables, played
with a few objects, and wrote a little code. But we were weak. We need
more tools. Like 
operators
. We need more operators so we can do
something a little more interesting than, say, 
bark
. And 
loops
. We need


loops, but what’s with the wimpy 
while
loops? We need 

Download 17,18 Mb.

Do'stlaringiz bilan baham:
1   ...   66   67   68   69   70   71   72   73   ...   90




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