You are on page 1of 25

Hn,1 t•P".i-.-.1....

,•
.11nd vie, wn,1 Tabl~ 6 !>1'CWI thf': f1vtt1, lat,Je tor Unr "'"" v..
l•• ;zoua l!?D .. _J9J r.akt' t\Oth f•P'""VDf'I' ,,, f,ikf, f.111•,
18 ,. ·''l~& (to..,.. 6QJ Ohf' it h;n rt.~ ,o:1c,y.,111g wnu•
1 " I lo,,, noUtY IN.,,,,., tl,'l(trt,Ottol tHJ"(OtOO l,:.,pM.,nd
Noc~ th•t th• ~lo! •~OOMl(Jlt"

I · I
lOc,c:;t o~ o,,..,,.., II 11 ./1
1, >ko • bool• "• • ouryop,rotor ,nd ,. u~ 10 comb••• IWO co1wMon• •• The re,ult•oa
1 ••P,,.,_, hl\fll
l'ttrlogolORop. r1tor II
latHf, fo, 1hc OR _,.,o ' - tt '' ,r,.. ,r MM" or,,. optt•od• is tru•, or ,r bolh orr tru• IAblo S shOwi ~ , •~:,,
•a..' "'
'" • 1u• lne !JU!

Tabla I kOT ()otlt.COf Tr\itti


1th.a\,~ tollow1oe svrn••
Ld u, Jo''.:! .iri ("...-imp(~
Opor•fld1 OjWrMt02

:.r
,.,,. .,...
t., ut "'"
1,11<
'""'
UU•
'''"'
••is.t fnllf
,,.,,
'""'_
Tal!M 5 OR Op,efatot TNtlt T•bl•
ror t",.1mplc-, con1.idf'f thr r•oreuo,
(15 > 3) II (ls < ZS)
Th11 r-,,,afu.ltH to: true, 11 ••lse - true

·W01e aprogram to dttmon.__,-,,.-,-.~,h••-u..,- ot- ,h•.-,..


- ,-co-,-0-:R-_--,.-,.-,-.-----------
....
I public clJ~~ LKlCalDR
2 (
3
4
publ1c $tat1c vold ~~1n(St~S"I arss{J)
(
5
Syste11.out .pr-intln( ·c1s > 3,) 11 (lS " 25) is "' 1
6 l
7

le-t us ~ 'M>l'ne mott- «-••m~e

8olh t • ~ •r• fal1t


·~~101
.,
-. ft11; ~n1,-on o trut
5ftond f'•PIHWOn 11, trul'I
• lO ~.JQ '""
U1,1,:,
Boen ~... Pf°K~, • r,, true
Notf' thl!t U1, logic.I OR ~rob h,n: a ~ p1'1antv th.an the rtlol'!OnOIQClt.l'tl_, age•
3. lOfl(:.tf NOT Opi:initor UJ
Jc Th,"' valu,e, of a1e .afler
T~ log,c.,I NOi 01>1,.IO< fll ,s > uoor,_,ot(J< '"" 11 Wfollrn ,nlrOC11 a,• "'1Clo"""'111>cl 11,• losoc•I NOi ope111or nep1e5 let us sci~ .:mothf'f ~p1;
th.• result of•~• ·'PrMUOn follow,ng ,1 1o., ,r II•• •"ll••u;o,, rttvrnu t""h•~ ,._ tho loto:•I NOT OIK'rato, writ,• .....,
r 1a KIPs ... S'Ulff • 1,

§;.
C o ~ Appl<4ltaonl rx 001 rato&. ,n 1...,,1,
al,.(!. andJm;;ft v.i-r,.a lnhlt.• L 1haw1 u,r· uum r11H~ roe •u\~ rnH -u1A ...
htn 1hr foHawm~ i.ynra,K
oi:,urand

~p'tj

I
Tt'h!t I NOT OpiMIQf Tu.1th T.W..
t\ u, \tt ,m i:~mp~r.
1(15 > 3)
NDW ,hi~ WIii <?Wit!U'1t(~ (IS,

1 true -+ ·hlsr.

Progr•m 5.
write I c,fotr•m to dtmnn,trat• •ht ,1111.t cf tht ~ I NOT al)(!ntta,.

1 pubUi; cli ]rJO


2 (
J pobllt ~title void ~~jn(5tr1.n& ~r~s(J)
I ~
·-~:~
Syst~.0111t...pr-1nllnC' H l~ ~ l .. P(lS 3)) ).;
•s
jnl
' )
7 l
Litt u, M!C ~ome r:nort C!•ampt~s.

tlut: (5 ► ,EJ 11 li!\.f:


rt,ill ;U ~ IS KU

Nott that t~ logol NOJ' ori~or hat ii) hlih:r prC('~deflte thatr. 1he rel.atiOft.al (l, ariillmtllc:(IC)C1'illtot\

:S.2.4 A.Ulaomant op,r11Gn v ,/1


5o In VoU h,we beam lll'ting-1ht'l 1,•,lAnm~nt o,:MJrlltor ~•, Wlllhout any fvnnll 4nucd~ct10n'i l!e! lHi· ~l!C' wh,itl. .i ti A.ss~grnr.eM
,ope1:11lor d, U'LM tD a1.,:1gn ~he. v;a!ll)i:, of_.; n t;,tprcwon to, 3 variable

It hn llH!: fcillow~t\l: wntiX

variable= e~prcssion;
F11r ~ampU:!. c1111rurdt'.1t the lollDW!nR •n•6miient
ag@ ·-= 15:
lbt ~ue:of DCII!' after a~f§nmantwjll ·b4t lS

Lr. u, ·~ ri ;JJJo~r ,h fl mpl1'

s~ "" sUlfli + l-;

~ ; ' i f . l U 9 atflll 1MiW W'iM •I. 19


ID, lh< n,w -,Ju• ol 1M ,umafirr ••"I"'"''"' w1U u.- , , ·"· __,,_ Th,! foHOW -1'\C ,.bf, \hG /11!,S lht m.1-n ihontund opc-tiil!>I
"~'u"""nl th,u ,n, oogtnal ,.,1fu.c 011hr w"' "'-'' ,um• I 1W ui . . th<' old"""' of'"'"'"'·•"" ,ddlnt I 10 11 ""
WOUl<I dl".I t1t1lh thf" ,,,m,int \ttlr~I ,um
\.to,r the .an,W1"1 ttw- nrw-v.ar.,., of lht ·,u,.
• I, • • t
1h1" IU'l"rTV-fll 0p('fol10' ti t11npry otWIOtOI

.amph• l • 8 !tC'U th('! V~llltit '


••
Olffeft'Me b"tWttn ;tnd 1 •• • •n
tM• op,i•r.ato, n, .m 11 ~rnent oprr,110, 11 wu. .a v.1u.1blt f'ClUi41 IO some v.ihJt. Fot r• ••
n,lmt-d z tqual to 8
Th~•• ~,or is. .J comp,11,SOf'I opcr,1t01. vou us.e rt 10 cht<l tf t,Offlt1IM'tl tQuill, J,Offltthln& else. f,ti._ 7 1!.t10t1.Nn

C.ht'tk.io ,t th~ VIili'° lh.ll Z hOld\ h t:'QLIII io 8 V' ./1


1. Shont,.andAi11arnme-n1 Opttrat0I"\. ✓
Jtvi offr.n tew,al ,.,.,, ,norn al tktt .&1-s-tfnmN'II OOtfaEor th.It ,u• nlcnrd 10 •" 1ft.Otthof1d asJJOn""'"' oprrotoi
c-••mplr, con,l<l'N thr rr1llow,og SUtl'~nt
1 • l , );

~ c.an rewn;_.. the jbQVI:! au..11nmtt1t ,t.it~ent :a,

l u 3;
Ttlli vrr,ion of thr 1i.1tttment use1 •• ,-hc)rt~ a,"14ru,~nt operator, 801h ~,form- 1hr ,am~ atnon
v.tl~ ot \/,mable t by 3 A,1,0m.nc, 1h.,t tht- 1mnat V'Jlue of z w.a-. 5, 1,,... orw value of t wtll be8 IS• 3) ,lh.er ti
the .lbovt' 1Jto11rm. fll

prl+ 1::€61·111.,..___
Wntf!., PfOl{'affl to dt'fflOn\ttiilll.'i lht- USl!.Of th~ ,honn,"d ,n,,anment Opl'f.tt.H

I public cliau 1o
2 {
l pobl10 •t•tic void ••ln(Striog ••s•II)
4 (
s 1nt l • S;
6 SyStf".out.println( '1 • • 3 i, • • (z •~ 3)); Z • • 'J I\ 8
7
8 }

Ja'lfa of1N'I -.horth.lnd a.)\,llnfflf!nt opento,.. for all of tht- .u,1~ bloarv QIIN!«llOlrs
r,clud,es. the fotlowt"'I synt:;i,11;
v,1ri .1ble • var111ble opt-r,1t 10n upr-euion;
an ~ te-MtnN'I, m1nc th«- UMX'thand QP('rator, as
... floltf'ICJ'l'fflrf\\
vdriabl~ operation expression;
Fot e....ample, a ,1 , 2; can k rewnnen ., ,1 ~• 2~ ••• Prt lf"ltr'rfflrl'"

fhere ,ut 1wo advantiftt'I of using VM>Cthand 01.u!gnment ot'fl•tors: Po-.t dto ........,..,.t

They~ a lltl~ hft or typlna nmt- Pn! a«Jtlhbl(

'1 The use- of shorthand operaton ,r-11ulb ,n .in tffldt:nt code,, 1hey itrt 1mpltt-mented most efficlcnttv b'f' th J.,,, , . . . . P.,.ar-d
run•bme environment ,u compared to their kma forms. lt>t us no-N u~l"ld tht pQStfu: ind prrfm opffrjO:J' ill

r,,...,..,._,,_ A ~ • t - 1"I Ooffato" In , .....



.t• a• l
.. ... •· a .... ' ,
1. . . . " • •I
.a •• ti
•'-li/n
,.,.,
~/• n
'
l1
~a.a"" I
• n
0
s.2.s l ab.. , .ShonN11a 0pe,•1or.
lncr•mcnt and 0<!cr•m~1 O~rato,. v ./'
o,,.,ng P•oC••rnrn1n1. You m;,y •ncoun1tr .. .,.,n "'••Non,'"""'•"°" m.oy nood to,,..,..,,."' or dcc,•m•,i • ""•b'• bv
l ,n vour p roar.irn fo, • . .rnoto, "'-vc • look •t •h• lollow,n1 """"'•nu;
$U1!1 ~ Stifn • l
. , • • 1.
y .. y - 1;
l ~ ,u,~ff)(",nu c.&n •'1.o bf rt"Y.lr1ne., ll\
su~ .. _;
X+<t>

Th•
tht follow,nr -tt •nd
0i>er•1ontwo w~rst0n1. <alloo ln<,..nuint and d-•rn•n1 oo•m1ors ro,p,c,-Jy, Th.., •ro unary OP<'toto,., ••""C
- •t•C'.1ch

/pmi, hter,tment. when th<- •••~•n1 ope,.,o, (>♦l" put bof.,.11, o,,..,.nd llko....
✓ Postfi, Increment, wh•n th• 1nctt-rncn1 oo•.-.10, l••I , put •flor 111 operand 1,,,. x-
v Pn:fi• docrement, wht,o the ~r•men1 op.1•t0< I·• I 1, out bolore ,,. Ot><r•nd 1,..,, x
v PomlJi doaemeoc when the douoment ope,ato, I- -) " pul •fl•• i« °""'""d Ilka, •

fli'n'M!~. the Pr,: ,1.no, lor bf.for~ M\d U"M po,t i.Ulods for aftt,t:

Usu-aUy. tbe <>Perat-OfS •, Ot - - •re us«t ln .sto1\ements 1!11.t JCt+; or ++x; Thtse staten,enl\ tMflCe lhn·;i/\till' of, Thi' two
vers.ons of thr OPtriltOr\ hl)\rf th.4- iame effect on the operand {1 c:, U\e hnal \.'ak.iit of ... ,c and X♦ ,. ,, th• s:em•l-~ , .
you can use X....-+, +-+x,. >t~ °' x . , ••prenion-1 or~, o.anof t~ lafll"' t'IU>fl':Ssions When tJWd osetpnmo,u; orpon
of Joro,, ,:xprfl:Slons. the-,, imptXt •.s d,Jfrrem h~t T.\bl4-8)

... Post il'ICremefll Inti lrt,l. 1 112 flf'll US(', I ~ inal"'!\a'nt


P~ ,ncre-mtnt
-· ·-·
10ll ~ ••11, Zl$2 ...,l:s.] f#\.t i n ~ thton VM'
•·· Post dt<rwr,e-n, t'ICI: 11.-. lU1, 11 tJO Firu u,.., thende<r~n1

• · Pre G«fem@nt l•u J'A0.11.isO f:lftl ditld!.t, th~n U'iti


'
Tabla I : P,,. and Polft 0praratora u &;i,r.H~n•
Let us now unclf't1tand the postfix and prefix opouttor, an ,,~111cr der.ill Co'"we, t~ followma ,tatrmeot,.

00,f,r,Utw,,. in JiW,l KlM I 81


\t.1!.-fnt'fll I I
"' ...
\t.th•tnt1nt I l •• 't.
'1a1 ..mrn1 1 ,. Y ...
,l\ccard1nc 10 lht• ..,, I
· • rrnrn, '
ot VI\ 1. lht• \loll~...... vou nrC'd lO k'Krtmtt\t v..;~:,,t oft try J ,md il\.\!tln the -..,Jhw of V to I AU4Jffl1ne: I~ •
"''° I
ot \I. \l;r'ldlMB y • 8"Pl:"' l • Y•. w•u,.,,rit' UU" lhf.- w.ilu•ol y 1 ,. •u1n a 1.0 , . y11"ld1l"g, • 7 11 wilf1'," mtrt'mrnr lhe •-- f°9'91 4i· ~· ••P'•"'
mil]
r ~ .-: ~ lnufflwfll, t
; ...
1

m
' . : P0'-,'1'.t r.rit,.,.tt'II. I~ .. ) '•'11 ll!Mf p
. , ~ .. afu• )11" ,' r "
,...,..,. .~ ,
1
f~wt•, 1 PMtf1 • ••r>tnl !Qn 1v1lu•1ton

~ be>, ~ ~IO 1hc>-;::;;-,,
on -".',::nt h111_u1t, tl1en:•~•nt •
b
FiAUll' ~ l 1-hOM (hf' m~morv ,1111u, dm,nc lh(" ~.tlU-lnon itt0<·u,

y
I • "':.,,. ,
••
b, 1 1 . • lil\lu"v } 1fl I JI I
C 1 ~ .. n..-n in< remrnt
I ~
Ftgu,e 5 3 P0tlA• tnc,emenl
lc!t U\ under1,1.and 1h,. PIOCf'\\ \h"P ~ )1..,

.t ,n~hallv, lht v.i1ueoof v.itwbl~yn. 1 .ind tht' v.tluc of v;,u,al.tlt , 11. no1 deftntd
b . A) 1t 11 a Po,tfu; opN.tnotl, "°" fir1t u~" \\-hkh I\ 1 hence, 11 .u-s!gnc.,d thl· ,.,afur 7
C. Now, you lncn:-m,,,t the VilUf' ol vby 1 Thu), l>lt> f!nJI V.1JU1"' of v • 8
Thr loOow,n1 Pro«11m lS tfle ,ml)lc-mH11.1non 01 i:-,utf SJ

pii-Hli:lii·a-------------------- ---- ~ ,
Wm~• Pto1r~m ro dt'monw.ttt- tttf- U1~ of the ocxtf,11 1r,c,e-mrt11 optora1or,

1 publ..1.c cl.au Postfhlncsaecr-ent


2 {
3 Public Sl4t1c void ,utn(St rlnR ••II'[))
4 (.
s int y • 7;
6 int l C
y• •i
7 Syst~~.out.prtntln(•y: • • y): &fil,;ci,
8 Sys t~.out.prJntJn(Mz: ~ z): j

9 } B ~
:. 7
10 ) l'
Stitem~nt2·z • 1 ♦y.

t,ft,,e, MV•'- drhnt"'d robe tht- n&wv4'k.llP ofy~r l hi.sbttn Mtdtd Sotf yts 7 then bothy ilnd Z w-¥ ·QYe ttltv.1lue 81.f'.
1t fir,t mcrt>mt>ntt. th~ 11alut of v ,1nd ffMr, uses- ,u Vihlt .s ,~n in F1sure 5.4

82 f KloS °°"1'•~..,, .zn


C°"""''" ApjJ!icotionS IX
•ntt
[El--~ I •Fm:iJ,

lf,ou ro !.,•, f>tefl t ,o-,gt..tlon ,ov1i1unt ion

nen,l:!'n,bN 011:1 riJI~ In lhl:! Prof1t tl'itirl:'meni; fir1UrKi-c~n1. lhcn uitl

F,r..tHC- 5-5 '.llhOv~ th(! rrtcmor,i l!Ul IU~ idurinfi tt,c L."VatUllUOt'J OIOCCU

z: y
.[J • 'J
- ..... in& fr 1
"'
b. s " ~ l'l"I 1o«emeo1 v } .., - ~ r"-\.r:. ~. y,
.
t. a· Jl: ---- .. l'htn-.te '

Flg1.1t1 $,'$~ 11-■fh: lnOr,r,moni


1
t➔orn 11. th~ ~1i<!pw11c e•1l~anauo11 of WIUH hbppen~

~. ,n,naitv. lhl! ..,~hJe o I \'~tlabl~ viS 7 :ir,&J t~c w.tue .~ ~ti1lbl<: :11~ undo Hned as ,t h.!J ~ ,1ot.,1:teen d~cl,11 ed fl'.!t,
b, Wh.en )'Qu Ui~ ihe: JHCftt op~~tion. t ht:t -.•;.lat l\ fif!it lntr't'meni~~d; 1hu1 1he w1IL;i! al ti bf!(_of1"M s; 'l h~ ¥J1ti1Jbh1 z.
1r, rnn1 nt. undcllnc-{I \l11r •J lhr vailuc o! ·1 hi,~ l'IP.1-~n l.l~1.Ht Wl
c:. Ahtr lrn:;rerru:11"111(11 ,ht v.1lu,e oJ·v L~ UJ.cd ~"' • ,Hsfen~ 10 :. 'fJ1u~ r bt-ccml?-5 8
mplcme-nlni100 ol FIJlUt,C 5.S

Wiitr .ti ~1'011,film '° d_elT'!OhlH.itc the u~c oi tht-- pH!.ffal ll'!Cf~me,-l OPCrtlCO
1 piJbl i<· cla5:; P.11ef n:rnc,.,_cP1~.0t'
2 ,(
a pubUc: sl!~t:ic void mi'1 .l n(Str1ng aro:;'[ B
41 {.
s lnt y • 7;
.G int : ~ ·H Y,
1 '
.;,.. Y1.)'•
,,
S~s ~-err,,. CU.L. W1'1'1 !'tlrJ( !• y. ~ ~
8 Sys.::em. aiu't .priri'tln(,. z " . , ?,};
y;. 8
9 ) z: 8
r.. ~
18 )

In wmmary1 fot the ~-.am~ abi:r.re


lj,·. Thi! p0 •.-~,,., operatcir /if$1 ttt!i_an~ Li lit ~;due Ctl UltJ var~b!t! or,. ihe h1h :,nd MM ,NV.nN"nem:s ih-e ..,,,... ~ o'f m~ o~,:i"rtd
-
• 1 he pa!T'!r, operntor jj'lt i~_
cr('l]t(:'nt:s t.hc ,.r~lut al ihri?.opl?t.and ,•md tbM in>41n5- tt ta l~I'! 'i.~ rt.1b~ GIi tht' Ith
w, u1, Si."~ 50f'llt" mor~ cGmple~ al ~,~ion,; ini,;~118 prcll, :1nd pcst-1i1t,ot,tornt(C)f1.S.
E.11.11mpl~ 1: I! :,.. ,,. 4a; ttrl!!i ltle "Vaihm a1 x ?,. " ,f ►.,l:

...... _ .._: ~--- iiUriic I ~~


r-:-•
, 7,a
~ ..

r
- • .. !
. ..: t
.•. •
!
:r .•
0 0 I
..: ::.:'
~
, •
•,

~

~ ~
=
1
5 -" •
: ,0

...
., .." •
~
iii
Ii I &
....
:,

j/
E

-••
..
... . ..
l

.::.

E
...
V
l' t~ i <
§

..
I
II j
Q
•,
e

.. K
• • •
.•
0

.
• •

0
}
•,
.. 1
" - ,. ,--
•• "•
..
=
~
Sa

E
.3
l

• .. - -

••
¥

• •
1

• •
• ~

'
• • -•• •
'
~

-•
-••
• -
>
0

• •• 7


- •

~
.,

..• -
0
~
--a
t-
~ C.
l-
• ..•
E

E
••
-
E
;
-
s:
::i
C
s
• CP

- C f's! ...
-..
II
.::; .!S,
t .-.
c
l"'i
!I!!!
C:

~
~

....

,.. ,.
-'!;:'.
UI
:.-
-t - i ,,.
E. .. .;.
0
•.. 1; ... :.

a
.... C " g
fl,i; i::t
; lflc --..
:S
If"!
l"t

• = ...II(
C
::J ;; "•
....
C

..•
:ill
;;
T
~

)II;
,,.
N
.£. ►
II C:
..
E
~

IC
...
..a

~
X
I!!"
-0
u
:,
ta":.,
:::ll
li
~
'i; ~
t? l >
-= ~ £
-t.,

+
• -5 ~
C
N ,.:. """ '! r=

-
.i:
iii
I
Jr.

.-..
~

== -


7
r5 C
•~ iTl- •
~
C

A i<
5
;;
i.,
I
i
.,•
"t I --; s
"•


•;
j
•-
:•

!..
"";; :;
:,
-
J!
,?:
;;- •-• • • MI
-. "'.!., ...
;t ~
h
~
• : ~
~

"C ~

. .
~
• I. • i 'II i) •

.. ".
~
0 < 0
0 E
!
o
.J I• 2~• 1lf 11·
.> t.•!
...• 1i .:.. ~ l r. ,!;.
>
., >
• ~ ii
:
-,••
~
I~,.
-•• .....
! • -f ~ €
.....
..
, 1! f .s
...
- " u
; ., .;
£- &: ~
.. • .
•, l!l
• [:!)' .. •• • •
.• B' •
.• -
·s .. .• ~"'
-• ...,•
• " ffil : ~
• ;. s ••
. ®'° !, (3 N
-.+ ,• .-•
~ ..

"P
" ., a-
. •
• El~ - -• • n ~


• I
II I
~

~
...• , , ~


.. ~

C E
f !lo
-"•
0

••• ~ ••
~
•••• ,.,-
5 • C
. •
••

I• •• • i •• "•

•• a • c
t "
"►
~

~
•> "-•••, 0..">
c
E

0.,
"I
.::
s 0
• !
r -0
j! s
=
li
~ ;;
• .?

~
= •
s• j;
~ -- ~ e.
>
1 j
, =-•..... J-
.?
~
.,,"
~
>
f -
C,
,: : !:; ..,.. I
...:........
l-
-
~
1! N~~ 'O
! n 'O" ,.. .!!, ,.., 'O
ii
.1·
N C " C ~
'. ' ~
•••
f •I• • 'I '1i "'" 0
g• ~
C
,
0
"'
,.;
;..! ii.:,,
.;;
•"
oeo
i ..• ..ii
.s: !l
.
il •
11 .. j •
••
-..... ~ n~ • • - ii
-.,.. .-- .,~
=
., .s; ,.&'. -; t9
.....
C
-;; iii
~

'a
•> t

.
.
• >
;:; .;;
7 •
£ : ti.
.
-
!J!
a.
11
• •
0
•. I ...~.
.
. •
E
s
.. .
I&.

!
..
E
l:
• E
3
bamplr 12: 11 'r - 'S~find1he vi!ut ol ." i
•-= • t11 u • "')

1
,e,\tl\H \t•J d,. 1 ♦\ m,4tb.iltd on tht Pff'CNfttft(.f •nd UUX!,Hiv+lyOf tt1t ~r
I '.,.,.1, .. ' P11r,todtnc.-; Ptr<~dfnte ti.t.hf prN>f'.ty ot Af'I oprntof ~<eordjnl 10 ... -.1
~.:):, 1GJ· [;lt 1,llrd W\lh II TM P'lf'"4'f'l(t' h ut.cd to dtt,.,m!rl(! tht ordN of tv~
~•JO op,:r•to, fhur t1ff! cliffttfnl /f-w/J of pttctd,ncr from high lo kr,v ,\n
·-40
'""'
Auod11nVtty: I( two CPtl•tot'S h.avt Cht
•IM:.\!v-""l)f t • S • l.nola!Y,l'utof~ •fl from .R!&hllOl«-h• Thl$1Sl!1mM.1tos: tiwdut1
• Posifa •fl(le'"'fnl I•••) ,1rtl u•e (• • SJ Ui•n ,1'Cttf1'ltnl
• i: ftJt.1 'f .. "11 or a: - fl • fin,,! vahJ1> ot • • 1
=7
• Po1tfl• mctfftN>N C•••J l1r111,1u (• • 0111'1"'1'1 inctt"'-tl!
'"Al,tht to l•h I 11.hf,,11 cpr,.. ,on 1n '" ' r ,p,1
'-
---· f•bfci ') UJON'li lhtJ.r,1• optf'.i!or, ftoml~ h~toltw ~ ptw(tdl!r
5.2.6 Condlttoru l Operator (7:J ,.Jl
Th~ COnd1tlon~1 OPf'i~I0t h ~I\.O ullt-d J ft'lnGlyopt/OlOt bi•t,1Ul.t' I\ hJS thrri• opcri1ndt I b \Vlll,u ''

bool~an•expreisian 1 txpre.s.sionl exprrssion2

of Ill, tht -.,,.,,., ev1lu11 .. th• boo ! ., n ·••Pr•<sion whi<h 1M11t11llv . condrnon.1I , 1.11•m•n1 If 11 rv,l1
;p,. theft th.- -a.. of the rnhre ~prcsslon 1, e~press-ionl; othefwi'K'. thr- ~.1lu,, o f thfo rntire t•IJttSJ~
<ond1hon.l OPl•r.ito, W!lh lht- \~Ip of SOmC' t1..ample\
-
~•~1,_ 1, 6>-.&h.Ul,J'I' 'l
,;c:,ai1 t> 11 < 4 l\ lilh,r 0
4 ) 2>!f11f;'.1(' J

1ltof tht" cond,non.11 opec.ito, 1~ to ~1 .i v,mabJe-.,x oqu•I to thr lairtrt or two vartlblna.
program

13

to ftnd 1hr largtr ot IWOvar-i,bles U~ing tht co11d1hon..1I OpeQtor,


clas, r1 ndMil);:

publ1c SHt h void ""'in(Str!ng •rgs[ lJ


(
1nt. ,1 • 7, b 13,
int max;
OUlPUf
max• (a> b) ~a: b;
Systc-111.out.println( ·H.llf nu..ber 1s: .. • 111ax);

·, , ,.J Precedence nnd Assoclatlvll)' of Operators v ,./'


lava has • w ide v.tnety o f os,er..11ors whfch c.in be ul4-d »multaMOu1,ly to Mlllvtt In IJPl'Qllon, Wh,n men thin one:

Doe,aton. art used 1rt .tr'I ~s.sfon. the Ja-_•,1 runtime e~romnt,nt deade.s whrch operato, should betvalu.tted fttlL TNI

KIPS Ope.-......
'°"1ruter ApPlcltionrIll
c,.,c1-.10n '" m40e 1Msed on'"' Pf~cflltncc and :u\O<Wh\l•t't' of lhC! op~r.-10,,, ,o t.1pl•1nrd bClloW
"'-<edtn<11: Pre<.-dt'nc• 1, th< pr,c,<lty of an opo,•ror •«O<dlnl to w~l<h 11 t> ev.,lu,rod Lach o,,.,.•10< ""' a p,o<r,S,n<c
uJOCi'-'lf'd w,lh "t """ o•tt.-dtnu• d U\Nf to dNt'fffllO(I- 1ht- ordN ol cv.t!u,1t,0n of o1n r,pru,,ori ir,.-OI\Anl morl!' lh•n OM
• .,.,.,., .,,.,.. .,. dllf<rcn11,,...,. ot p-,cednn<~ from hlah to low AA ~1,11or btl<>Of"'~ 10 • hl)!Mr '""'' l< ,v,1u11NI

hf\t
AsSOCil11V1ty. If INO operatOfl hil-Yt' the ).fl'Tle pr~..-d~nc" lp•I-Oflt,.), ttw'n 1hcvtare t'1thtr (r.'.aluatr.d t,on, ·htt to Righi ' O'
from "R.,cM 10 lth Ttw. 11 tNmf'd a\ oss«JOfMll', whteh ttlls 1t,(' dlrHno11 ot r•e<uf'OO ol opt,ta1ouCLl"h to A•aht· or
A1Rf't to Lf•fr'l VihN' op«'fitor•. ,n -Jin 1.·11pr"t.'nion h.tvt, the s.a.~ p,e-ctdrnct
Titbit 9 ·;how\ th~ lava opcra1on. ham thr hlthnt to ltit! l(w..t\l prt<ndtnct', :.1onfl ,,.,,,1t, lhrit t1\t.0<i.11N,IY

11 .Afr~ Wtdi·•
Mt-lhodUII lieh 10R•£flt
I ✓ II
Mflffl~MU\\

.. ~ or no,tfis ,ftCttt'!"IClfll
f'rt 0t po\.lf,. OHr"mtrl,
1 • Un.II\' pu,,. ,,-,.nu1. fUI~ to l..tl
O!IWl\.f' ~OIT•plf'fl'H,I

l<>c.!till NOT
hVOf' u1.II lw,>cUU
3 ft•t;ht to le-fl
now Db,«1 CldliOn
Multiok,laon
I Df'mlor l~h 10 A,c~,1
• Modulll\ (rm,.a\nd('fl
✓,, " Addtt10!\ ,ubtf.ctk)n
~
i.tll lO Mi&ht
./- St1Wt1 conci.uen,-tlon
< lH'SlN"
✓ <• lC''i'i 1hin QC eq"pl 10
6 L.ef't to ffiChl
> Gre,ur ttw\
>• G,~1•· 1tian QC otc:pL,Al lO

"/~ EQIJ,11:o
1 t..h to Rcht
,. Not~tO

8 && ~o,:a,~o
9 II l.OIIC4!0fl ::::: 1
10 COtlOtflO(llfll ttern.,ry) oper1t0f'
' A ~ and ,ti-orlNnd
"""''°''" ✓
• .UJIIJ)lnCPl Opt filtQrl

"
~ Jbthl lO l«f'I \...,A"'
n
••
,.
'lk

T•bl. 0 Prkedone• 11rd M•oda1Mty of Openiton -


n,._.,..~,,..., /.., h.,~
lf't U\ 1;1\.t~ an t'•.1mplo of th" fonaw,ni r•Pttuion

• ~ = - ,_. ,. . . -.
• -~ L ~•~ • •
·a ··I
. ·• , .
.l b -+ C
So WOOld lh, corr,putet ,e...-,1lu,ltf' i1 - b tit\\ .lf'\d lhe,n add c to ,t, ot would ti f'VillUt11<- - b • C flflt. olod thrn •Od;, to , ( ~ _J!;a
.•~,ult? If vou ct,«~ th,, i.bavc t.>Lue. both thr • 1r\d -c>pl'ratori h.tW" 1hr umr orececfttrw ,., rs,.
th.It means the 00,r,~~ w,,t~ 11 p,ftar mt .._ • - - - - -
. - -----
w,11 ilppfy QSSOt,anviry tul~ fOf 1h~ din-en°" or tXetutlOn 'hhtch 1s '"Lc-1t to Right
- u, thi,s c.u~ (\tt ptt!ct'ftnc~
_ ,0w sin - • ,1 O '"'IT'IOmtn;tr I\IOC'Jibll(l't c,f Ol)N,1to"·
To1blc 9} n-.~
mf'iln! t ~ t th<- c • ort-sslon , I P,Ubli - C l ,HS t. l •tlvn.
1 (
a - b • c
W111 be ""aluo1tN1 I\; .,3 PU'Dllc JtalJ< w,t~ &Jln(Strlna araJ
(
s Sy.U•~.ovt prJnt1n( · 1 t,.
(,1 - b ) • C
6 • l •
SySt"9 out.prtntJn( J • l • S .i,:
,lnd rtOI 7
Sy,t.... out.prlntln(' 11• .. (.3 t
,I • (b • CI
So w N t ,f You rully W,U'lt l~ tclff,S>t.at e< to CV,olluat, b • C t1r\l 1 Wf'II, vou m1aht ~\'f" .air
VCMJ un J Jwavs ch.Jnllt l M- CKdn tn wh.c:h ;in t:irprM-.1on <NIii ~ t"'V.1luo1ted by uunr. brAC:te.U. Add•M ~ v1
II ...~. to iJnder\til~d th, loaJ, M owowr, ,t redUCh thr, .Jmbogult'i j fl ,, ',OU ma~ ,t Clt'at how th~
~v~tu.m~the: t-llp('e')'fi!Of'I
lat ll\. t• h • .anotht-r ~.-.arnplr O-f' opt>ratoo: ha'i!nfl t~n ~lf1C ptttOdrritt'
Syte•.out , priotln(~six ~ 3 ~ 3),
~ OOtC)U! or It,;· lLlt.ement w,11 be
Sh 33
ln11eo.1d of
i iJ( 6
11 ' ' bt-c•1.1'-«' t~ • ~ , 1110, 1n, ltlf' 1tr/r,o coneotC'notkH'I t,,n lhl" wm-, prt"cc,dcoc:c ..., t~ • opt'r•tor tor
P,t"U'dt-riu row Sin t h'" lob1e- 9). As the. assoclilttvity 1$ from ·t.rh to Rlaht fo< this,...,.,._ tht." cooc:o1tt'-~tton of "i
the-su,n1 t qu iv.alen t of 3 hb\ pl.a.ct'! hr,t fhr t('\UILlnf unne 11 .pm COl"lc:.lten,iHed with the sttmg rqu~•t'ftt of
U\, OU1PUl •1oiil 3 3
Lei u, lie<- Whijl happens w'hl"-fl V04J U\f 111, f0Uow1ne .\t.it.emf!'Mt
s~~-out prtntln(3 ~ 3 •" s1~ );
n,,, ttnw:-, the output of the u:.11c,mc,n1 will bt:
6 six
No w. Q\ lhC" ~ operatot in th,• ,rr,11groncnrf'naoon ha$ tht- s,unf' precedence ,H U)II • ~ta tor for odd,non (see prece-dtro
u,.cs plate fif'lt Th·
row 5 '" the Tobit': 9J but l he auoc.iab\/1tv ts from 'lrft to Rcht"' fo, th15> lev"el. the add1t1on ot 3 w,th 3
string e-c,ulvdlent of 1ht- t t"\ull,\flt is th4'"n co,,c,ate-natt'd with the stnna thi1t follows 11, iM"C you tht- output ' 6 5,(1('
To t •w- preftrrnc:t, to t h-e, 1nu•g~• ;,ddmon, vou mu$lU'1,('I br.ckets uic.
SyQ.e-i . out .pr1ntln(' six •(3 • 3)). When"'°" UNU' ao ~clot thk Chu t1w'Pf, th• WU,,,i!'l'IU
Th" COrrt't1 output o f the.- sut.e-mt'nt will now t>r MObile IIIYf'Ot)ile;
Six 6 ayt,'IObtl:e • ne1o1 Hobih();
..... aa_ IK<os Coq)ut~ Appl.c,1qg;, OJ)ef,:01'1tnJ.rlj
Wht{' .ii PfflQ~.)tt, 1to t1
1 pub he t l,a:i.;)t ~◄wr.nt kl
2 (
l
,4
pub.he \tllti t 'VOhl t!'!ltlri(StrJn,g ~re~J))
·[
5 Sy.stern .c:rnt . p_r-i ritb1( ~UK ,., l ,♦ 3),
'
?
a )

SjstertiflU,t . p1"'i1'1Ul'J(J ,. 3 • . "-ht")


Systr!1:i,.01L1l.1println1( · 1 ~h c • ,(3 f l))
9 }
■ 1:1 s.~ nae ff]O\'I np_o_~JP! iv··
~
f;i r li~r W:,iJ tu, ..-e 1~.11N1t 1h11 u11r15 ,~e concept cd g cf.us. vou,c:an m~111 tho rnlfffJ o,t
mtthod1h blr!f'~.rtU
:u,d biJh.!Lwou,, ~ Ultr~<lrfftWd am 111 IYPC ~ ¢Jh ~~ 1'11fl,1 be· (CUUtdtHC'.'d ,If. a ;/(JU, typ~. llJr,d
1
Ob,IPCl mutl,m,
tr#X'• GYNnnn 1n o'b.l~ ,of a ~i!lu typJ! 1nvo~s.1wo ,;t,Fu
Ji D(:cl.1 ri ng OWlttnb~tl of th(! d~r.s iVjK! ,
'"' Allocaunu nitim.c:iry fo, th~ obirm wht!,~ diJ1aC1 or the oWt>ct Yn ~ s.1ore,ft
lhe n~ O-Pfr■1to1 h u1-~d 1o.al~1e mumOfY rontio obj_l!'tt, 1ho obo'.•e mwoi1~os r2~-.? tru, fc)~fow,r,g~(l'lti
Cl .1~£11,·tme cbjcc:trrnme,.
objcctnntn(i .. nt:W (ill'Jlisn~rn~o
Herc, Cla.ssnn!!le Is the PJome af'u~o ,,u, thnJ ~, brilna lrntsnf1att:d (1, Chr! dillsi ~e [n-;.ran~ •1 b!?if\v ,ui,;i!ecf' F
objectm:ime ,, o v.i.pJble o, th.~ type Clns:.n1r.1e •~t !$ ~lnn i1ea1eo ltt uf re1Jfus chf Hob:flc· t.f1,s th1u yaustuct~d
,;ai,tter,
, .... ,,11:r.-"
Mot::::a c•u-. ~~tll, : · li'lll :1tcJf
1"411
.A'Urlbu1 ~ ll,bn lo1a U'.t1m.!ltr VJ.rubln
• MOCUI • .Ol•I illll~f - ~ 011:artnJ
• :;;,,an, f~•if
~
• lM~
Cm~, • t 11cJ ,cull
·• WN¢1t .. l11l.ir riltillJ~
• e.amr.~ p 1~r1, ut~: 11clw'rfJl 1
• lJobl'1rJ11,111
,r,
Sl1,.nC'..tHil
1:r.dC.a!la.
)r"'- fJ~ r !V.fl"!e,-.::t
flk ~:tr~•)
111.ke,•,mmu
Fi9L111V S~; Si.:l'llirn11II, .-.pm •n"..aUon ~r tr,• M:ot.11■ Clau
Whr.ri ,"Ou Ol!Jt~ a" •ob.t'ct o,,11tu·cira,u type. tht? s riUC!rnt'11b wiU hrro.'tliq fo.Jlow1n11. :S",n1u
,.,bbi'l~ r;,yHGbUe.,;
~t1bf h! • n t..~ Mobile!(.);
n...Mal A1'1, ,firl l-'U-11 ~ .J n I

"'J'illlll"tt'I• (


,. f,,Tf ,,'
. I
Ftt~• S 1: C111.a1lnD Ml obff"O ot IM M:,blle, Cl11t
mm-
'-11)1111 •tw, -t.fitfl'!nte btl • rir,m~.t .µ~ hPt (f' I ht! mtr1•,J •Mi •n obtf1t
I 1ur,.... tnT,lf't l ""
cont.1"l I w~rt,h. lo, 1ft ot-lrtl. I w.1ra1hl<t (Dntilffll lhf .-<fd0'1.1 '11,,!4'1• the> ei
1bot't f¥mr 111 tNU:r ,tv1 ~ t:"''~11~ •i 11n ,;11<1,,.,, ,ind not tM ""'' J,. ,11"'11
._ -
~tq,f-J A"I tf"
vou can ,,tso totlow11•,1- COl'T\btOf"d \yftl'111 IO dHl.itre and 1llo<.tlf' m•mory tn on< )l,ll('m(!nl

,
Claun,.. objrctn~ • nrw Cla,1nAw{).
lf't U\ nc)IA, (tl'llf:! VoltO,n, ObttU\ U\Aftl ih(· nr.- 09ffill0f'
Mobil• •ylP>,on,x • n1·• llobllo(),
Mobil• ooySoo,un11 • no. Hoblldl;
Mobllt ~y81Jckb~~ry • nrv MobtlP(),
Tht- n,p..- OPfr,ifOr in t-iad1 ol 1two J:11hovr \I.Jlttnffll\ will ~UCkllP ff'lf"mot"f fot Hth ob;«t 11 lhf' run ttmt" ., lhown
f;.iu.,. ~ 8
myiPhonoX myS.Jm,unc ow8111d1btrry
~
MOdf'!
·~
Modl'I Modtl
1..S,
IMS.
C<,laur
Wf'-«ht
""°"'
Wf"lli,t """""
Wt'llhl
fioQ1n 5 8 ; tn,tanc:e U..-iory ~ i i o n
So lrt w qu~ Iv rrv,rw .iga11'1 ~ t "'' be-rn mt.nPoo~d ffrfffr:
• °'
A dast ,, • lc-mplat~ bhHCH1n11.pec1fvm1 lh(.• llltnbute$ .and bllhlVlour or OblrC-l\
• 11 ~,a 11. a d.t,1 type 10 cr•atf' ob,ecu
• C1.1n ts~ 1~1ca1 mn,truc:i WM~~J.S ~n Obtffl h ,1 concrete ,,ul1tyuccuP)·•nc.JpoC.f In m~mory
■n s.s The dot(.) Opcrlltor ✓ V
Once tn" obi«u have bt-en CIN:l1ffd •na tht Mf'moty 1'!:-11 bftn i!illot.itf'd, me-mber nn1b~1, .1nd member ~thod·
be ~CCNSrd u!tint tflf' dot(. oPi"rator Synt-x of thr dot Operator i,
ObJna.ae:4·~ rVartable.;
Objn~""-~•iftb<-N1~th0d();
lt"I u, i t t ~KJ-..,_ to us.e- lhf' dol ~ t o , to .U.$tln -nlue,s to ltt.t membtf v.au.11>1~, of the Mobile ob,t<U
90 I KIPS
(Qmpu,t, ~
Mohl le Mob1 1~0.
1
MObi le mySPl'll!t'U'1
""°bUf ' l"l}'Sl ilc;ku,~rry n~..-
,rr.iviPhon~>;;<tolou,.. •shak Ill
mySr.~suog .~cl ::i '"4
:yDl ockborr,y. W-Nah't. :: 121
Thc-1e ~t~;r-men15 will opdatt- lhe m(lmory ~ ,nown m f.111,urc S 9-1hr d11;a '°' ctt'? ob,ec1 ,, '~ ttp1rau., h
.-mother
mrtifthon"X my»mi ung my81A~~trv
~ MOUr'' 1G
IM5il IM~f iM
:nlou - -•• .; - • ...,.'!!"!'."I"""'"
I
Flaurll s,o- lmunce s wllt1 rJnt1
S1m·,t1,fi,•_ ',i'I-U c-M u1 1c! -, he member ffll!thach, a~ ihown below
i ?hone>:. Oi,t1JN11fflbor. ( )
"'ySa:1Surin.st.artCal .1H:
r.iyBlack~rr-y. Endca l l O ;
■D 5.G f.Jprc&s lom;
1
I~
Dfl
Now tl11)l yov \,!'ide~t,nd \l'iJti:tblt•!,. and 0pCfJ10 r\1 li.,t u~ ptO?t!rlV derJ.n~ wtUI ! ,nn CXPICl.Si
An eA.Pfe:uror, 1\.., com~l'~tion ol COfl)lll 111'.• va,ub!~ , opcmtor-s, ~nd mt-lhOd t:JII~. 'which ,,{I
(.()1tWUe te-d ac«Jl'(ljn g(O t~c
S)'nfa, of the l&1ofl"-'£C · AA eipr<-ss~ol'\ when evi'.lfi.1.itM tetutns 11 llr'ltJlt \"11
ro form a com¢,i:.a e.'lpfe$f, Dn
The vJ!Ut- c! 4,1n ~p•r11slon an be ;n:Ji{lned to n vat11b!e ~ a,mblned w,th athfr v;,lutr.
'cM c-•n be rormNI UM~ o,w,,1110_ ,~
li tf!tlll~. vauah':e-s, .ll'ld mii:!11'\od ~rri ;u~ 1fmptt! i:i~prcs!,.taM:- Mare,ca,npl~.,; e~mei1
whlch •,ou run~ itudted In. ithl~ thliptct.. When sc\M:lrol op,:raro n appe~r ,;,.. ao e.~oress,
on, vcu use i,rrud~.M:<" and
ttHodaitv_,/)' co fllNc,min~ haw-the o_F>CrJtor, are gro.Jp~d 101 L"Y2i!uanon
Java e.pre-\~rons c.in b£, ,c.11~11Jt"l1,{'(j 11110."lnnoti$·l)-pc1
5.6 .l Ar1Lhmctfc c,iprc.uion /
An arithh1c\ic,c-11~-s.loo h~Pffl:Wfit.S.~ ~fc:,11.-,lu<-'- Th(l'y an be further cat~ d ,nta thice iub:-,-pes-,.m1metv Jrnqf"r:
te;;al and mb.ca !.>Q)1•Mi10n~.
l. lnl~t!r ~XPl'l!J-SIOll t/'
s ,,~ ma-.-."" a-. ,1nir, itJr,er e)_:prenion
,.,n 1.'XJ>Jenton cot1tc IMing int ~con, ta 11ts il~d ~,"3rU!~ 10In~d by u,thmettc opor4'tor
An intcgt!r t,ip_re-uH:Sn f!V:1lu.:,1es to .an ~nteEt'J'val'-lc Co,,~r ttf~ follO't.'fnE oec.limuon:,;
l11t :aJ x, y, z, l~nt;th. , brev~h ;
So,rie e.umpl~-. of-the mteger «riIf)t@)1 om, 1Jf.l11ro. th~ .:ibo~ -d ttl;u·at;o n, :1r,11
• ll -t- 5 • lc~gth • breadt h
• l3
• x • ()' ➔ z) • •)( .. (3 '•y)
~ 2 ~ ~ • X ~ Y
~ ~
~tOU ir, JlW.O
Z. kui r•D,-P\llOn ..I' rors .i,linc,Ati,n,,u1op,,
'"'I
m,nu11u ,a.l\d .-,m,bSn Jul'nc:-d trw uithtl'\t'OC ~
~ (1.,1,npl• J· WU!f' tft lffPfl\»ctf\ 1in U'II ICH .,,J • ~, • •
An cnw, · 100 :0·11.•1n,n,g
t"Pl'e'~,.,on Nilfu~tes. 10 i rt,I \lllue con~!"! ,~ follow•n, Oct:t)raflOI'\\
..,,, 1•••••b1 1 ,
flo•t i. •, y, :, lenath, brt,dth, f •~"'p&t • .Wrt!~ 1n c., :,rr.•'«! in Jn:a to, - ,1-: •
J'
SCrne c.•~'TI~ oft~ rNI t'11P,MW>nS u,1n, th-t .1b0vt dtct1ri1tton11rr Anl. ■ ly•t
lenglll • b•~•Ot~
n.o • a, so :z,,,,..
"'I--·ir
• • ().I) •y) (....-A.mpw 5: Wtl!.# c,.-, t " • ~ t - ~ &'". Iii-I IOf f
l.3 ' x • lit y • • (y. ,)
♦ t,f
l, '-'1t1•~ !'~Pft'Hion
/I
An "•P"ti~ wttith conu•n , ml•tureof 1nt~aer .ind tHlf"ll)fHiJon, 11,ino""n~il mfl'('cit•P'">"'°" G~n lh" toUo-Nil:I i
Aftl, l • ()~••■21/(•I•
dKlafibOn
inti, x, breadth;
Ao~t y, z, ltngth;
Some- e,,Hnpln of u,t" m1~ed i·-<Ptt'H~n, u,1n• lh~ .abow dtd,w1noni .,,
JenRI• •
21.9
2 • ,c • x • ;,
• S,U
(3
• (y' t)
X ,.
5 6.2 Sirin& expr•nfon ../'
A ~,nnc f'.:Pft-\w,t·- r•«,,rtitntt lol ,tnn1 v,lur YOli c.annot ,tocJ -,nd ,ubtrad ,t,,nfµ,, Mf' nurr-btrs. bt.11 J.w.i doei P1
OPt'l,IUH for (on(.lllt'n~t10(I Al \IIIOft~ !iOmt< t"~.&mptMof m,rw •~.1pr~rno1n .,,r·
"'.tbc"' • 'dtf·- Vt~.. ,ri,ult 1n ",lbcdr("
•234" • 'S.67'" w,tl ruu1t ,. '214567
·rhc Jr'-'•' of tht1 hgur,_• h - • .,r._.,, i squart ctntlN'tres.,
Ass\ll'TMft;: th.at ,he oren \l,,ri.al>lt- i'IH .1 dive ol 2S. tht ..~ mine r1Pfnt.1on w,11 rC11ufl rn
The .arc·.l ,if th4' f1gUI"<' h 2S '\qu.tre CPntllltlr(•S"
5.6.3 BooJoon (or logical) ••pumlo'1 .J1
°'
A boolto<1n ~•presi•oo ,~presrnis ,1,, boolei,, v.1lut tror f al 14' tn .addition 10th<- o11,1hrr\.tuc .and rtlatfon.al OPf't•tot1.
.a boolt:Ml f-XPte-ssion c.,., cont,m booJtirt DPffilton. SOmf' eump,ln of boo,e.an i,xp,c-1.ilOM .art-
~ldt•r.Gr•d• "" '8' II fi~a!Grad• • 'A'
a I• b && a 1= c
Aje > IS
(a - b) <• (c • d)
1 •• J
1 < 10
APff!'r hllvJna INmt .Jboot v<1rMHJ1. typto1 ot ~ \ . hit 1.1, lum how to write thtse ~S>ttss.om 1n lava.
£ample 1: wr,te an exp,rt"u,on 1n Jav.l for sx' • l.n • J· (ICSE 20111
Ans. S•x·x•x + 2•y•x ♦ y
Wmple 2: Wr,te- •n npreuion 1n Java.for (o~b)(r ..·d)
111,yRtisult. ion1NU11twr • 1nth1,111Ctr:
An, (a+b)•(c•d)
H~ is a ~ I l'f'l)resent•bOn oi mt- w;aliuoon
..... 92 I Kl>s Con,puttf AnalJt,UIOnSU: OPf'l'atonmJ~
-.... i ■
>
..
-.... a
;!I -
.. I"' 'Ill - ,.....
E •3
- "'-I I - ...
JI 'X
,.,, 'If
..,
t'II
~
C' .... '!!:I ....
-i:li ~ =i'
i
-
r -.-:
n, ~ rt Ill
'="
~ (
""c::: .!:..
l """ =
~
-
i
:I - • ~ 1i,

• ~
ttJ
ff'fJ

ia 1i 1i :, i !

!!\
i .. i ~

ti•I,
Cl

.i

I8 ::r
r]

~
:;r
I?(
:,
s
..""
\ - •

I Ir ~
';"
~
'Q
-
.. ?
Cle
""'
~
f' e
,..
-
~

5
3
TI
0
'-"',
...

:i ~
'C !
-
;;ii
;r
9
--
'""
l l!fMII','. ¥1'1~n th•rrw11 of ltl-f p1 rv ••
1 '"'T-··
-,,iuult lOtlC"~('-f' .1nd th,.,r rt-·..u!t k of doubl• tyl'>t'
1009
In< ~.7.2 Eopllclr TYJH' Conwnlon, ✓
L-r - J loog
.ilu~ to~ bV11t w1ruble-, 1hp conv,:ri•Dfl 1'1-~1nor b<' p
'.M Rt~lllh.at the bottfld.il-1,Vpt! .::.:.n Qni, h06du1
Agu,.. ft..10 E J ~ T,-pe Ev.1wt.on
Apply inc tht- .tbch'l' con\,erst0n , 1eo\. ,,om toe> co bottom, tfll' t'V1k.i.lNM'l t.al6 p~ .as toHows
COms>tler rnds lht> c•prtn&on S.•nu ne-ithet- ~nd n of the tvPf' double ,ne compiler mo\lr1o tot
1 ll ~~lu;ite·. .1nd df'dUUi th.ii ~ .thef oprrolnd 11,.i ffo,lt 1hecornP.~' tnOVff, to IM' M tl steQ .
.3 t1ere the <omoik-r ldi"nnnM th.at Ot\f' .-f•fld 1.,. lone. \0 theottwt opt"r.l~ t\ (Ot'l--ffl.ed to lonl .1nd 1n.-;
of Iona l'fPt
let u1, now l'v,lu,}te the follow1n1 t'lpt.-u1on wh,c" t1as mi•ed d111.a lvr>M
Eumplt Z
dOuble •YDoUble, myRe.sult;
float • yf loat 1
l•t n\Ylnt;
ch11r myChar;
,nyRe.sult •ylot ~ •)'Clwr t "Y'lo.it / ~yOoublt.
He~ 11 a pjCtOh.al ft"P't-Wtlt.lit'lion of thl' t'VolhH11'1oii proctn
111yResult • •tint • ..ythar • myfloat I ~ 1 ~ .
l ~-t d~Dl~
l
,nt
ch1r
J
f
dour I"
I~bit ~J
-1>1•
Fivu,r• $,11. &pc-Nuon fJpt Evlll~Uon
Ao-ptytoa thf, •bove Convt't110r\ steps. from toP 10 bottorr, lh' ·-.·~lUltlOn c~iw, PI-ICf! OS follow:, 1
8 )' • l i n t ))(~
1 As tne drliJloo opcr.)tion tnn ill higher precrdenc.e. 1t tS ~..'Nf Mt Stnce operilt'ltd mvDoub1~ 1•. double, t~ oth,,
g
Ol)t'r•nd myFloat 11, c;onvcn~d to a doublo ,nd their c'1,1,ilt 11 oC double-1yp,w 1e Sy\t..,...out .pr1nt ,.n(~;·y 11
2 Nr>;t l!t the addmon between ch,u..cter (t1yCh1rJ .md double d.it~type ~bk- 111yChor Is con~td to i doublil ,u Systett.out .pr!nu.nC'".~ I·
and lhe-,r rrtuh 1s of doubko IYPf' 12
13 }
.. 94 ,_ Comp,u1er Apphc.tc,,n ~1 Opftaton '"Java
Wht!'o the rtrnl l ('tf u,
ia{•g ,, e:,..illu~ICd w1th1 4n 1-it('~ {m.yI l'lt}, r,ya nt 1\ t to 11 dOrlibl!?-
u ult I\ o,.datiblt '
s.7.2. C.pUd1 ~pe Con\l"e,s~oni

AUIGffllUK l\J)e COl'l'l/t!~1Ct,~ :uei hetpfot but 1he-., dong\ folh l c11I Prollr~rnmins nr:,t'd~ r-or ~il:il!'IIDIC, ii \,'C)U w.an.t lo .lH1gn
1n inl ..-a1u~ to a byte-\1:.i ti~ble-r the c:onvctStcir1 v-.,11 no:. be oerlonnc-d
- . illl'torn111'Q'.:h~ b:,ec,1n1c I ~t Wti1e-dm cype f:!t :'ffllil 11,..., tn
. ' '
1
~i1"·than ~nt Reea!l lhl!iMl'I!! bvte~ia type.oon onlrh#!a up,LO 8 ii,iu wh-cr~,, 1he-1ntdatil Lype-r.anhokl vp to 3.2 bh1; S
k!nds; at cw111~~on~ ijJ.C i,erformeo fofc-cfullv ov lh~ Dragr.omrrmr und ,orc-ca!tC'd C~PUCII. 1,
To ue-1,~ • convcuion bet \wo !m:omJJ11 :1~1 "' i:;aH rTuu,1 be- u\td, A c,a.,,t 1\ iimP=ll' ,.,, t,,,,irtlr rv
It\. Wftt,li: I
( id 1ta'"''~ pl') exp f'!estio.n
H d:n: a-t)'r,t!· pr, rr1lt1YC diUi11,•ne. nie e1i; pre1 i; ton m,1v ttr aton1111n1J ·~nilblr. o, .arr.i ·m•prc 1,"'(a
Scenario l • Le; uJ. Wl'\~K'h-'i eh~ xeruoo wh :to ar, inrci::cr ,.1,. ~f·thl'.! ,a11a·.i.iirui: stdllem~n,
tint oJ (·l'nt) 7 ~4S.
lh(! .:abo\re ~I .Jt1Jme-rrt w, l'J c-a~t ltu~ d01Jblt> v.alue 7. wS wnto ia11 hn tltl i:, vilu~ of '-'t30Dble ,I i wtll be 7
W~n you Jll'tform SJ.. It c.:1;, 11:!,.,d toil los\ o1 iJ-rm~•on, /11, you know, rnlC'ECQ. do not h,-~•c fr:itnonat i.Ompo:nie-nt~. Ki
~ " a dOtJ blf" 111 1
i. .n~f8'1t'd to •1"1 ,ri~t:!f):e, type, 'the, f r11,rnoni11 c~ropOnl!nt ~, lca1it. It• thri c:ii_.1,rni:ilc, 1fie ...~,u-t! 7.;•~ I~
uunc.ated •o 7
s.e.Nrfa 2 • Lei ui Cj0n1-1~N 1hr K~nAtI0 whetr a fiol'II v.nluto <i t-i;pac:)U 1.rrto :1n •nt("CN l \ oer tb~ lollo;;.·; u. '\litlNman1
na~t K • s. 2sr.
l ri.t )'
'I 'I! ( il':'ll) I(_.
1
1n tltt' ilbov_t! eumpln; the f~t v.:il.1-1e 8 2$ wi~l lyp~uinw-an 111eege1 The,;,.•ah,e of 11 y.illl bt>a
·t.iio:e th.at explicit castin1 dOM rimt aifK: ·ttie- Dl"ifllmi~valuL•. In 1h~,eia..-.riii~~, the-ast &aerator UneJ da.evft Jffoo tr.e •.'3Jue
afffl'l1ble- :K: ~ data type o! vilnable:,; ;cmama flo.l_t ?.MfluM vaiu_~ of B.25 ,n thE' alt,~r p.lrts oflhe prow-am a1 thaW!fl
in Pqram 5.15
·ih::fiklla____________________~----
Wnt•_a ~ m to dfffl0nrtt11te- flo11t to int e-itph~II coth'tlfffan
~ public c,lass r.loirtToi.,,t
2 {
J. P"bl l ·C !i--t11t,Jt ,.1otd rni1h11 (St:rlng nr~l
4 {
= 8 . .2.6it= ..
,,
S 'float iii·
.
int y~
••• ~ • ( Int
9
11· Sy!.tmn .. oLJt .prlnt lrl('" )
11 Sys·t:iJtn,.o~t--111r1nt 1n("' >..
Ii
12 .}
1:1 )
r'l...&-a ... 1-■r•, rtr I"-• i<IP1 ~ I .9S

-":;e.
C

..Ii •..
M
~

• ,.<
~

0
~
Cl.

;;

- l
I t- T.

• \ t
0
0
5
i

I
l
\
\

6 i.nt count ~ ec,
7 double a\i~rar.e.
B
9 au~~~ge ~l<aooblc) \u
10
n S,ll'sten.ou.r. pd:ntl11(""t.,,;er,:u1:e 1S ♦ ,ilY{l l'";•G~}.
12 )
13 )
1■ 11 S.B OulpU\ IUtinr, 11rfnUn ,Ond ~•lfll ✓ ,./
lhe Syiu:::m cl~n conuhu ~Mr~I UTtt,iu1 '(.JrinbirJJ Qnd marhod~ Tii\-,, af •w(h 1,1s;efu" m<'~tiodr. .H~ pr-!nt:S"O . ., r,d
prl nt'( ) • llhtti, \Vfft,ti; .,
S~c-m, O\.it. prfnlJ n(mm,,i.oc<' l 1
s·~,am .. out. pri:l nt:(f!'!t,!',if;un~) I
the mc-,UJ1c uu1 U1\:c Y,1rlaus to,tr;, ui Yol.l wO! 1-t-tl lli lh(I <'tllmPle) bt,fcr..v S(irh un1cmcm.11 will print 1hr mrno
uin,,ln11w1rtdQ"""' b1J\ lllOf(' ·~ ~ '1,\J1ltl1J' .dlficii'1inu Wlillf! print In lll'IO'JM Um C:illlOI IO-~ bcn111r11nnol the Ot-!il
dl_'Jll"'tihs 1hc, n~~R~. i:,rint lfnD\:~, lhn r,liij(J( tl)Q'lflln (tn the !ITlfllf:I I.rte; Ali OtC1Uli ' 011! outpUl ftom 1lfr( ~ob
pr int 1fl, ar r,.r:lint :-;u:ih~.n\cnt wlll ((H'ltinuc 1from ,hat. pm1·t¼o", l,<,I u, ~c ,oMtt f! ,1mple, oJ 1,h NC \.\~\flti1t1n"
1·.--:;,..- ,_·::•.li~•-·,_li· ~
.·..-
1· -~-------------===~,--
ii.~~-..-. ,.-,_
A 1:1rm11r.1rq demc,r,\tr.a cfJ'!I the i,rlr:\u1:;a~men1
l piibll,t c,:l.i$t, Prlntftcll'plcl
2 {.
3- public 1otatJe vat.d. ~,ll.1.1f'l(Strine ,1r-g:.:(])
4 {
'S Sy,~~- f!Ut. Pri ~t ('" n r~t- lj II I! ~); I. . .
6
7 }
·s.y,5t:arn, oi.rt.prlnt("Se,,ond Line·); I
t~.V'fl~-g.i!M'~~ J

~J
_.ell ..._ - --·-
8 }
•9 i ~
~ pragr,u·11 cleniomtri1ttfni the- ..,nntfn ".tiltemerH
l pi.ibll.c tlas'§ ll t'.h'lt l:Xil~D l ,::,.
2 [·
3 putdi~ s1.:a11:.-ie- ;,,tc,id milin,( Str1"i: arcs())
4 ( Ft,01 tu,
5 sy~t e~.0111t.pl"" i nt·ln('"Flr~t Line "'); •St.!-ci>nd l.

6 Syst ·ec.. out. pr'lnt'.!.l')C"'Sccand llrte··);
7 )
,8• }
Qiw.1ror, ~ J,iva ~l
tt·iri::W·
A • ..---------
d•mo"''"'""'
progr,m u•• of> .,.,1,1,, '" ••• P'"'''" ,tar•"'°"'
tN!
I put,llc:
cl~~s Pr 1ntf•J~ple
vo,o -•ln(Strln8 ,rs>(l)
,- §iiil® i
1 I
pubUC ~uu
J

s
6
, J

{
tnt roHNUllll>"r 13;
Systei1,out,pr1nrJn(rollHOiM>Cr)t l~J------
6 )
lit·Hfill@a~-------------------~~-
""'°"""' d,mon..,•tt"' th•""' ol • ng • nd • ,.,.abl< '°',th<< vl• _ ,. ...,._.roon,
,i11
l pu~lic c1•ss Pr intE~a1fPle4 MY Aoll NUfflDt!I 2l
1 {
3 public st•n< void ,,..1n(Strint arB•[J)
4 I
s int roll~u-t,.tr ~ 21; ~lJl'ber 1~: • • roJlNolftber),
6
SystM.OUt println("My Roll
, I
8 )
,aM•/1:Uf?❖-~--------------------------
A rxos,•m otmonma.r,.,,g hcw.· 10 taw c.1lcu1anoru. In ttit pm,tln 1tatement
1
2
public cl~s~ Ft ndCu~
{
r - ™m
~ . ,:11
) public static void ••ln(Strlng arg$()l
4 (
s lnt r\Lal 3;
6 Syste..out.p~intln(~Cub~ of • + n.- + • ls + (nUII • n-ura • nura) ) ;
1 I
a I
NotP the 4M or br«~t>ts vou c;;m 11,t'I the- nme outpgt without b~t, but tt,e use 1s advtstble for code- clatity,
,.,,.,oon
YOU I nffd brtKll'ets heft bt-uu-,e the • op("f'.ttOf ha-; hrjhet P,tcede-oce 1h.an ttte • Opef'iltor SD It WIii be f'Yllwud
94 Jku,s ,,.._ __,, ,.. · - ., __ f - - ..,.
• •
" ~
ror
A
a

I
IUfl\
wm.;;14

• \. ttu- ,.,.,e~ wn,:


11

.• ( . a.._a,u.-tri I(!
C.
0
1urn P lS
1um • 16

v1
A , An~er the following
D,ft•,-.qt;~ .._ l

Sectiofl 2 : s ubJttct•v•
quenlon• in ,hort:
b;; ... ty ,, ... .,J ' ' I ' QI
1h r•

o,
6 TM \fitltffleM, l"O) && t\• Ol tvl'l1LWtei to
i/1 61
C. ,• p:.itd - b,J\a,Y O;'WfiltOl'J.
A 0
D uuf "
B 1
7 tM 1,t.sh.•fflff!t (1 »OJ 11 (1, 0) r--.1lu11tft !tl ./1
C f,• ~
A 0
D tNr
IL
I ftw,sl.iffff'W!fltf1:.sljf 1 0h.llU31HIO ✓
A 0 C !Jll~f'
8 D truP-
9 Thf- t•plf1 uon 13 .., 3 g•vM w ot11-c,u1 ,/1
•• C Z
.
B l 0
10. the- expA'\StOn 13 / l gr.fl 11,. output ,/I
,. C 0
8 ) D
l 1 The llAlfffll!'nt System.out prlt'llll'W~ • • ) • 3). 9,...M U,i output ,/'
A ..,_ ll C 3) $1•
8 '1Ut 6 0 6
12 Tbt1 IP'■Ofei1-ion .& • B 1' 2 QMIS th<" output ✓
A 6 C 4
a. 8 1-11 ..t96g';i.l "-NO
0 ,._ of - ·
B.• State whe.ther the given statement$ 11re True or False :
-"rthmeuc op~1etOtS • and ak.o h.,~.- a un.nty form t/ s
2 Op~,.:°" = Aiid -:c--:- pNfo,m Inf" 'WllfflC. OJ)efill•OO in Java t/J C r~ _-.: L S,
J lht- - , : p r ~ 10 ~" t"Wl!u<'ltf\ to 2. ~ C
,-, •
4 The f""~1on 3 / 4 e-,ah,.1atn- to O v" L..
~ AA> • •
S. The- e-■pres"ion' l • 4 and •3· • •4- evatuatt- to 1M sarn~ val\l~ v" ==
b Thi, tiM~n .v • .. 7 f\ samr a\ • " ._ " ~ L, 2~
7 The- n.w Opf"m.o, .,loc.1te, men,ocy cturing runtlmt Y" C 6 Writ~ onr diftfftnc~ bt't#ffn I ~ IJr. OC>tfl! JI
8 ~stilt('fflN"ltsic=1 a.nd ••--=7 ,llfe\.lme ~ C AM ltw di'Mion o~raUW-r/': dnl"l6es ll'w !:.nt 0Pffi,f'd D o;h,, ,e<DI'
9 Thf'f"itptf'SStonz. 71..,san,.,ai:•1-•7 \J'I C
[; 7
(9') ~ liw ,em&sndfl ontv of the- 0.·,1Sian oe>cr•uon
Wha1 WJtJI tM' the tauh norfli 1n • ,tt~r ~~\Jr;q ~ fo'lorw1
10 lhr iii\l'QnmMI c,p.ar.,,t04 ,,. ~ a bNf'>' optfltor ,./'
~
,---, 1ntX • ..t
'----'
X••(l(•• •l··Xl·X;
100~ I k"'1
Co~ttf Al)bhOtCil\1. 1l ()Qti'ator~ •11 &.I'~

You might also like