— Scott McNealy, Sun Microsystems Chairman, President and ceo


± A single-line comment begins  with two forward slashes. x = 22; // this line disturbs me



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

;
±
A single-line comment begins 
with two forward slashes.
x = 22;
// this line disturbs me
±
Most white space doesn’t matter.
x = 3 ;
±
Variables are declared with a 
name and a type (you’ll learn about 
all the Java types in chapter 3).
int weight;
//
type:
int, 
name:
weight
±
Classes and methods must be 
defined within a pair of curly braces.
public void go() 
{
// amazing code here
}
What can you say in the main method?
loops
branching
statements
Syntax
Fun
statements, 
looping, 
branching


you are here
4
dive In 
A Quick Dip
11
Looping and looping and...
Java has three standard looping constructs: while
do-while, and for. You’ll get the full loop scoop later 
in the book, but not for awhile, so let’s do while for 
now.
The syntax (not to mention logic) is so simple 
you’re probably asleep already. As long as some 
condition is true, you do everything inside the 
loop block. The loop block is bounded by a pair of 
curly braces, so whatever you want to repeat needs 
to be inside that block.
The key to a loop is the conditional test. In Java, a 
conditional test is an expression that results in a 
boolean value —in other words, something that is 
either true or false.
If you say something like, “While iceCreamInTheTub 
is true, keep scooping”, you have a clear boolean 
test. There either is ice cream in the tub or there 
isn’t. But if you were to say, “While Bob keep 
scooping”, you don’t have a real test. To make 
that work, you’d have to change it to something 
like, “While Bob is snoring...” or “While Bob is not 
wearing plaid...”
Simple boolean tests
You can do a simple boolean test by checking 
the value of a variable, using a comparison operator 
including:

Download 40,57 Mb.

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