Professional Documents
Culture Documents
The + and - ope-WPS Office
The + and - ope-WPS Office
ator
scanbebot
hunar
yandbi
nar
y.Aunar
yoper
atorhasonl
yone
oper
and;
abi
nar
yoper
atorhast
wo.Forexampl
e,t
he–oper
atori
n–5i
saunar
yoper
ator
t
onegat
enumber5,
wher
east
he–oper
atori
n4–5i
sabi
nar
yoper
atorf
orsubt
ract
ing5
f
rom 4.
2.
9.3ExponentOper
ati
ons
TheMat
h.pow(
a,b)met
hodcanbeusedt
ocomput
eab
.Thepowmet
hodi
sdef
inedi
n
t
heMat
hcl
assi
ntheJav
aAPI
.Youi
nvoket
hemet
hodusi
ngt
hesy
ntaxMat
h.pow(
a,b)
(
e.g.
,Mat
h.pow(
2,3)
),whi
chr
etur
nst
her
esul
tofab(
23
)
.Her
e,aandbar
epar
amet
ersf
or
t
hepowmet
hodandt
henumber
s2and3ar
eact
ual
val
uesusedt
oinv
oket
hemet
hod.For
exampl
e,
Sy
stem.
out
.pr
int
ln(
Mat
h.pow(
2,3)
);/
/Di
spl
ays8.
0
Sy
stem.
out
.pr
int
ln(
Mat
h.pow(
4,0.
5))
;//Di
spl
ays2.
0
Sy
stem.
out
.pr
int
ln(
Mat
h.pow(
2.5,
2))
;//Di
spl
ays6.
25
Sy
stem.
out
.pr
int
ln(
Mat
h.pow(
2.5,
–2)
);/
/Di
spl
ays0.
16
Chapt
er6i
ntr
oducesmor
edet
ail
sonmet
hods.Fornow,
all
youneedt
oknowi
showt
o
i
nvoket
hepowmet
hodt
oper
for
mtheexponentoper
ati
on.
2.
9.1Fi
ndt
hel
argestandsmal
l
estby
te,
shor
t,i
nt,
long,
float
,anddoubl
e.Whi
ch
oft
hesedat
aty
pesr
equi
rest
hel
eastamountofmemor
y?
2.
9.2Showt
her
esul
toft
hef
oll
owi
ngr
emai
nder
s:
56%6
78%-
4
-
34%5
-
34%-
5
5%1
1%5
2.
9.3I
ftodayi
sTuesday
,whatwi
l
lbet
hedayi
n100day
s?
2.
9.4Whati
sther
esul
tof25/4?Howwoul
dyour
ewr
it
etheexpr
essi
oni
fyouwi
shed
t
her
esul
ttobeaf
loat
ing-
poi
ntnumber
?
2.
9.5Showt
her
esul
toft
hef
oll
owi
ngcode:
Sy
stem.
out
.pr
int
ln(
2*(
5/2+5/2)
);
Sy
stem.
out
.pr
int
ln(
2*5/2+2*5/2)
;
Sy
stem.
out
.pr
int
ln(
2*(
5/2)
);
Sy
stem.
out
.pr
int
ln(
2*5/2)
;
2.
9.6Ar
ethef
oll
owi
ngst
atement
scor
rect
?Ifso,
showt
heout
put
.
Sy
stem.
out
.pr
int
ln(
"25/4i
s"+25/4)
;
Sy
stem.
out
.pr
int
ln(
"25/4.
0is"+25/4.
0);
Sy
stem.
out
.pr
int
ln(
"3*2/4i
s"+3*2/4)
;
Sy
stem.
out
.pr
int
ln(
"3.
0*2/4i
s"+3.
0*2/4)
;
2.
9.7Wr
it
east
atementt
odi
spl
ayt
her
esul
tof23.
5
2.
9.8Supposem andrar
eint
eger
s.Wr
it
eaJav
aexpr
essi
onf
ormr
t
oobt
aina
f
loat
ing-
poi
ntr
esul
t.
2.
10Numer
icLi
ter
als
Al
i
ter
ali
saconst
antv
aluet
hatappear
sdi
rect
lyi