— Scott McNealy, Sun Microsystems Chairman, President and ceo



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

boolean isHot = true;
while(isHot) { }
this is the output
Java
 basics


you are here
4
dive In 
A Quick Dip
13
Conditional branching
In Java, an if test is basically the same as the boolean test in a 
while loop – except instead of saying, “while there’s still beer...”, 
you’ll say, “if there’s still beer...” 
class IfTest {
public static void main (String[] args) {
int x = 3;
if (x == 3) {
System.out.println(“x must be 3”);
}
System.out.println(“This runs no matter what”);
}
}
% java IfTest
x must be 3
This runs no matter what
code output
The code above executes the line that prints “x must be 3” only 
if the condition (x is equal to 3) is true. Regardless of whether 
it’s true, though, the line that prints, “This runs no matter what” 
will run. So depending on the value of x, either one statement 
or two will print out.
But we can add an 
else to the condition, so that we can 
say something like, “If there’s still beer, keep coding, else 
(otherwise) get more beer, and then continue on...”
class IfTest2 {
public static void main (String[] args) {
int x = 2;
if (x == 3) {
System.out.println(“x must be 3”);
} else {
System.out.println(“x is NOT 3”);
}
System.out.println(“This runs no matter what”);
}
}
% java IfTest2
x is NOT 3
This runs no matter what
new output
Sharpen your pencil
Given the output:
% java DooBee
DooBeeDooBeeDo
Fill in the missing code: 
public class DooBee {
public static void main (String[] args) {
int x = 1;
while (x < _____ ) {
System.out._________(“Doo”);
System.out._________(“Bee”);
x = x + 1;
}
if (x == ______ ) {
System.out.print(“Do”);
}
}
}
System.out.
print
vs. 
System.out.print
ln
If you’ve been paying attention (of 
course you have) then you’ve noticed us 
switching between print and println.

Download 40,57 Mb.

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