— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet83/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   79   80   81   82   83   84   85   86   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

you are here
4
primitives 
and 
references
63
Each of the Java files on this page 
represents a complete source file.
Your job is to play compiler and 
determine whether each of these files 
will compile. If they won’t 
compile, how would you 
fix them?
A
class Books {
String title;
String author;
}
class BooksTestDrive {
public static void main(String [] args) {
Books [] myBooks = new Books[3];
int x = 0;
myBooks[0].title = “The Grapes of Java”;
myBooks[1].title = “The Java Gatsby”;
myBooks[2].title = “The Java Cookbook”;
myBooks[0].author = “bob”;
myBooks[1].author = “sue”;
myBooks[2].author = “ian”;
while (x < 3) {
System.out.print(myBooks[x].title);
System.out.print(“ by “);
System.out.println(myBooks[x].author);
x = x + 1;
}
}
}
B
class Hobbits {
String name;
public static void main(String [] args) {
Hobbits [] h = new Hobbits[3];
int z = 0;
while (z < 4) {
z = z + 1;
h[z] = new Hobbits();
h[z].name = “bilbo”;
if (z == 1) {
h[z].name = “frodo”;
}
if (z == 2) {
h[z].name = “sam”;
}
System.out.print(h[z].name + “ is a “);
System.out.println(“good Hobbit name”);
}
}
}
Exercise
BE the compiler


64
 
chapter 3
A working Java program is all scrambled up 
on the fridge. Can you reconstruct the code 
snippets to make a working Java program 
that produces the output listed below?
Some of the curly braces fell on the floor 
and they were too small to pick up, so feel 
free to add as many of those as you need!
islands[0] = “Bermuda”;
islands[1] = “Fiji”;
islands[2] = “Azores”;
islands[3] = “Cozumel”;
class TestArrays {
public static void main(String [] args) {
int ref;
while (y < 4) {
String [] islands = new String[4];
System.out.print(“island = “);
int [] index = new int[4];
System.out.println(islands[ref]);
File Edit Window Help Bikini

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   79   80   81   82   83   84   85   86   ...   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