— Scott McNealy, Sun Microsystems Chairman, President and ceo


Did you spot the difference?



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

Did you spot the difference?
System.out.println inserts a newline 
(think of println as printnewline while 
System.out.print keeps printing to 
the same line. If you want each thing 
you print out to be on its own line, use 
println. If you want everything to stick 
together on one line, use print.


14
 
chapter 1
Coding a Serious Business 
Application
Let’s put all your new Java skills to good use with 
something practical. We need a class with a main(), an int 
and a String variable, a while loop, and an if test. A little 
more polish, and you’ll be building that business back-
end in no time. But before you look at the code on this 
page, think for a moment about how you would code that 
classic children’s favorite, “99 bottles of beer.”
public class BeerSong {
public static void main (String[] args) {
int beerNum = 99;
String word = “bottles”;
while (beerNum > 0) {
if (beerNum == 1) {
word = “bottle”; 
// singular, as in ONE bottle.
}
System.out.println(beerNum + “ ” + word + “ of beer on the wall”);
System.out.println(beerNum + “ ” + word + “ of beer.”);
System.out.println(“Take one down.”);
System.out.println(“Pass it around.”);
beerNum = beerNum - 1;
if (beerNum > 0) {
System.out.println(beerNum + “ ” + word + “ of beer on the wall”);
} else {
System.out.println(“No more bottles of beer on the wall”);

// end else

// end while loop

// end main method

// end class
There’s still one little flaw in our 
code. It compiles and runs, but the 
output isn’t 100% perfect. See if 
you can spot the flaw , and fix it.

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   34   35   36   37   38   39   40   41   ...   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