chapter 3 Java at rupp cambodia

of 35 /35
1 CMBUkTI CMBUkTI 3 3 ³ ³ sBaØaNnBVnþelx sBaØaNnBVnþelx 1> 1> s s BaØ BaØ aNn aNn BVnþ BVnþ elxKNit elxKNit (Arithmetic Operators) (Arithmetic Operators) + + * * / / % % ++ ++ – – – – += += –= *= –= *= /= /= %= %= P P P P

Transcript of chapter 3 Java at rupp cambodia

Page 1: chapter 3 Java at rupp cambodia

11

CMBUkTICMBUkTI 33 ³ ³ sBaØaNnBVnþelxsBaØaNnBVnþelx1> 1> ssBaØBaØaNnaNnBVnþBVnþelxKNitelxKNit

(Arithmetic Operators)(Arithmetic Operators) + + – – * * / / % % ++ ++ – – – –

+= += –= *= –= *= /= /= %=%=

PP

PP

PP

PP

Page 2: chapter 3 Java at rupp cambodia

22

2> 2> ssBaØBaØaNnaNnBVnþBVnþelxeKalBIrelxeKalBIr

(The Bitwise Operators)(The Bitwise Operators) ~~ Bitwise unary NOTBitwise unary NOT

&& Bitwise ANDBitwise AND || Bitwise ORBitwise OR

^̂ Bitwise exclusive ORBitwise exclusive OR>>>> Shift rightShift right>>>>>> Shift right zero fillShift right zero fill<<<< Shift leftShift left&=&= Bitwise AND assignmentBitwise AND assignment

Page 3: chapter 3 Java at rupp cambodia

33

|=|= Bitwise OR assignmentBitwise OR assignment^=^= Bitwise exclusive OR assignmentBitwise exclusive OR assignment>>= >>= Shift right assignmentShift right assignment>>>=>>>= Shift right zero fill assignmentShift right zero fill assignment<<=<<= Shift left assignmentShift left assignment

]]TahrNTahrN_ ³_ ³ elx elx 4242 EdlmanlMnaM EdlmanlMnaM bitbit dUcxageRkam ³ dUcxageRkam ³

0010101000101010 > >

eGayCa eGayCa 1101010111010101 bnÞab;BIsBaØaNnBVnþelxeKabnÞab;BIsBaØaNnBVnþelxeKalBIr Qñab;min.lBIr Qñab;min.

Page 4: chapter 3 Java at rupp cambodia

44

]]TahrNTahrN_ ³_ ³ sBaØaNnBVnþelxeKalBIrQñab;nigsBaØaNnBVnþelxeKalBIrQñab;nig "&""&" 0010101000101010 42 42 & 00001111& 00001111 15 15

-------------------------------- 00001010 1000001010 10

]]TahrNTahrN_ ³_ ³ sBaØaNnBVnþelxeKalBIrQñab;b¤sBaØaNnBVnþelxeKalBIrQñab;b¤ "|""|"

0010101000101010 42 42 | 00001111| 00001111 15 15

------------------------------------ 0010111100101111 47 47

Page 5: chapter 3 Java at rupp cambodia

55

]]TahrNTahrN_ ³_ ³ sBaØaNnBVnþelxeKalBIrQñab; sBaØaNnBVnþelxeKalBIrQñab; XORXOR "^""^" 0010101000101010 42 42 ^ 00001111^ 00001111 15 15

-------------------------------- 00100101 3700100101 37

]]TahrNTahrN_ ³_ ³ sBaØaNnBVnþelxeKalBIrrMkileqVg/sBaØaNnBVnþelxeKalBIrrMkileqVg/ "<<""<<" rMkilRKb; rMkilRKb; bitsbits TaMgGs;enAkñúgtMélmYy TaMgGs;enAkñúgtMélmYy eTAkan;xageqVg tamcMnYn eTAkan;xageqVg tamcMnYn xÞg;Edl)ankMnt;. vamanTMrg;TUeTA xÞg;Edl)ankMnt;. vamanTMrg;TUeTA ³³  

value << numvalue << num PP

Page 6: chapter 3 Java at rupp cambodia

66

]]TahrNTahrN_ ³_ ³ sBaØaNnBVnþelxeKalBIrrMkilsþaMsBaØaNnBVnþelxeKalBIrrMkilsþaM/ / ">>"">>" rMkilRKb; rMkilRKb; bitsbits TaMgGs;enAkñúgtMélmYyeTAkan;TaMgGs;enAkñúgtMélmYyeTAkan;xagsþaM tamcMnYn xagsþaM tamcMnYn xÞg;Edl)ankMnt;. xÞg;Edl)ankMnt;. vamanTMrg;TUeTA ³vamanTMrg;TUeTA ³  value >> numvalue >> num

int a = 32;int a = 32;a = a >> 2; // a now contains 8a = a >> 2; // a now contains 8

int a = 35;int a = 35;a = a >> 2;a = a >> 2; // a still contains 8 // a still contains 8

Page 7: chapter 3 Java at rupp cambodia

77

]]TahrNTahrN_ ³_ ³ sBaØaNnBVnþelxeKalBIrrMkilsþaMsBaØaNnBVnþelxeKalBIrrMkilsþaMminKitsBaØa/ minKitsBaØa/ ">>>" ">>>"

EdlCanic©CakalbMeBjelx EdlCanic©CakalbMeBjelx 00 eTAkñúg eTAkñúg bitbit lMdab;x<s;. lMdab;x<s;. lkçN³enHeKehAfa lkçN³enHeKehAfa unsigned shiftunsigned shift..

int a = -1;int a = -1; a = a >>> 24;a = a >>> 24;

enHCaRbmaNviFIdUcKñaeTAnwg enHCaRbmaNviFIdUcKñaeTAnwg codecode xagelI xagelI ³ ³

11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11 >>>24>>>24 00000000 00000000 00000000 1111111100000000 00000000 00000000 11111111 255255

dUcenH dUcenH kMnt;kMnt; aa eTACaeTACa 255255

Page 8: chapter 3 Java at rupp cambodia

88

karkMnt;tMélskarkMnt;tMélsBaØBaØaNnaNnBVnþBVnþelxeKalBIrelxeKalBIr

sBaØaNnBVnþelxeKalBIrTaMgGs;masBaØaNnBVnþelxeKalBIrTaMgGs;manTMrg;GkSrkat; nTMrg;GkSrkat; RsedogKñaeTAnwgsBaØaNnBVnþelxRsedogKñaeTAnwgsBaØaNnBVnþelxKNitEdrehIypSMeLIg KNitEdrehIypSMeLIg edaysBaØaNnBVnþelxeKalBIrCamYyedaysBaØaNnBVnþelxeKalBIrCamYynwgsBaØakMnt; tMél. nwgsBaØakMnt; tMél.

]]TahrNTahrN_ ³_ ³ a = a >> 4;a = a >> 4;

XøaenHsmmUlnwg ³ XøaenHsmmUlnwg ³ a >>= 4; a >>= 4;

PP

Page 9: chapter 3 Java at rupp cambodia

99

3> 3> ssBaØBaØaNnaNnBVnBVnþelxeFþelxeFoobb (Relational Operators)(Relational Operators)

== == esµIKñanwgesµIKñanwg !! minesµIKñanwgminesµIKñanwg FMCagFMCag tUcCagtUcCag FMCag b¤ esµIKñanwgFMCag b¤ esµIKñanwg tUcCag b¤ esµIKñanwgtUcCag b¤ esµIKñanwg

lTæplénRbmaNviFICamYynwglTæplénRbmaNviFICamYynwgsBaØaNnBVnþelxeFobsBaØaNnBVnþelxeFobeGayCatMél eGayCatMél booleanboolean..

Page 10: chapter 3 Java at rupp cambodia

1010

]]TahrN_TahrN_ ³ ³ int a = 4;int a = 4; int b = 1;int b = 1; boolean c = a < b;boolean c = a < b;

krNIenH lTæplénkrNIenH lTæplén a < ba < b ¬KW ¬KW falsefalse¦ RtUvpÞúkeTAkñúg¦ RtUvpÞúkeTAkñúg cc.. int done;int done; // …// … if(!done) …if(!done) … if(done) …if(done) …

if(done == 0) …if(done == 0) … if(done != 0) … if(done != 0) …

valid in C/C++valid in C/C++but not in Java.but not in Java.

This is Java-style.This is Java-style.

Page 11: chapter 3 Java at rupp cambodia

1111

4> sBaØaNnBVnþelxEbbtkáRbePT Boolean

(Boolean Logical Operators) && Logical ANDLogical AND || Logical ORLogical OR ^̂ Logical XOR (exclusive OR)Logical XOR (exclusive OR) |||| Short-circuit ORShort-circuit OR &&&& Short-circuit ANDShort-circuit AND !! Logical unary NOT Logical unary NOT &=&= AND assignmentAND assignment || OR assignmentOR assignment

Page 12: chapter 3 Java at rupp cambodia

1212

^=^= XOR assignmentXOR assignment ==== Equal toEqual to !! Not equal toNot equal to ?:?: Ternary if-then-elseTernary if-then-else

sBaØaNnBVnþelxEbbtkáRbePTsBaØaNnBVnþelxEbbtkáRbePT booleanboolean KW KW &, |&, | nignig ^̂

eFVIRbmaNviFIeGaytMéleFVIRbmaNviFIeGaytMél booleanboolean

dUcKñanwgRbmaNviFI elIdUcKñanwgRbmaNviFI elI bitsbits

éncMnYnKt;Edr.éncMnYnKt;Edr.

sBaØaNnBVnþelxEbbtkásBaØaNnBVnþelxEbbtká !!

bRBa©as sPaBbRBa©as sPaB booleanboolean ³ ³ !true == false!true == false

nignig !false == true !false == truePP

Page 13: chapter 3 Java at rupp cambodia

1313

5> sBaØaNnBVnþelxkMNt;tMél ]TahrN_ ³ int x, y, z;int x, y, z; x = y = z = 100;x = y = z = 100; // set x, y, and z to 100

 6> sBaØaNnBVnþelx ? :? :

vamanTMrg;TUeTA ³  expression1 ?? expression2 :: expression3

PP

Page 14: chapter 3 Java at rupp cambodia

1414

7> 7> karekareRbRbIsIsBaBaØavgØavg;Rk;Rkckck sBaØavg;RkckelIkkMBs;sBaØavg;RkckelIkkMBs;GTiPaBénsBaØNnBVnþelGTiPaBénsBaØNnBVnþelx EdlsßitenAkñúgva.x EdlsßitenAkñúgva.

   a >> b + 3a >> b + 3 a >> (b + 3)a >> (b + 3) (a >> b) + 3(a >> b) + 3

Page 15: chapter 3 Java at rupp cambodia

1515

taragGaTiPaBsBaØaNnBVnþelx

Page 16: chapter 3 Java at rupp cambodia

1616

8> kareRbI Methods mYycMnYnrbs; Math class

Math class Math class manman methods methods

CaeRcInEdleRbItMél CaeRcInEdleRbItMél TsPaKehIyRtUv)aneRbIenAkñúgFrTsPaKehIyRtUv)aneRbIenAkñúgFrNImaRt nigRtIekaN NImaRt nigRtIekaN maRtdUceTAnwgmaRtdUceTAnwg methods methods TUeTAEdr. TUeTAEdr. vamantMélefrBIr CaRbePTvamantMélefrBIr CaRbePT double double KW KW ³ ³ EE ¬tMél RbEhl ¬tMél RbEhl 2.72 2.72¦ nig¦ nig PI PI

¬tMélRbEhl¬tMélRbEhl 3.14 3.14¦.¦. Methods Methods

sMxan;²mandUcxag eRkam ³sMxan;²mandUcxag eRkam ³

Page 17: chapter 3 Java at rupp cambodia

1717

static int abs(int static int abs(int argarg)) eGaytMéldac;xaténeGaytMéldac;xatén argarg

static long abs(long static long abs(long argarg)) eGaytMéldac;xaténeGaytMéldac;xatén argarg

static float abs(float static float abs(float argarg))

eGaytMéldac;xaténeGaytMéldac;xatén argargstatic double abs(double static double abs(double argarg)) eGaytMéldac;xateGaytMéldac;xaténén argarg

static double ceil(double static double ceil(double argarg)) eGaytMélKt;eday eGaytMélKt;eday FMCag FMCag b¤esµInwgb¤esµInwg argarg

static double floor(double static double floor(double argarg)) eGaytMélKt;edayeGaytMélKt;eday tUcCagb¤esµInwgtUcCagb¤esµInwg argarg

Page 18: chapter 3 Java at rupp cambodia

1818

static int max(int static int max(int xx, int , int yy)) eGaytMélGtibrmaéneGaytMélGtibrmaén xx nignig yy

static long max(long static long max(long xx, long , long yy)) eGaytMélGtibrmaéneGaytMélGtibrmaén xx nignig yy

static float max(float static float max(float xx, float , float yy)) eGaytMélGtibrmaéneGaytMélGtibrmaén xx nignig yy

static double max(double static double max(double xx, double , double yy)) eGaytMélGtibrma eGaytMélGtibrma énén xx nignig yy

static int min(int static int min(int xx, int , int yy)) eGaytMélGb,brmaéneGaytMélGb,brmaén xx nignig yy

static long min(long static long min(long xx, long , long yy)) eGaytMélGb,brmaéneGaytMélGb,brmaén xx

nignig yy

static float min(float static float min(float xx, float , float yy)) eGaytMélGb,brmaén eGaytMélGb,brmaén xx

nignig yy

Page 19: chapter 3 Java at rupp cambodia

1919

static double min(double static double min(double xx, double , double yy)) eGaytMél eGaytMél Gb,brmaénGb,brmaén xx nignig yy

static double rint(double static double rint(double argarg)) eGaytMélCaelxKt; eGaytMélCaelxKt; EdlmantMélEk,rnwgEdlmantMélEk,rnwg argarg

static int round(float static int round(float argarg)) eGaytMél eGaytMél argarg Caelx Caelx Kt;EdlenACittMélrbs;vaRbePTKt;EdlenACittMélrbs;vaRbePT int int

static long round(double static long round(double argarg)) eGaytMél eGaytMél argarg Ca Ca elxKt;EdlenACittMélrbs;vaRbePTelxKt;EdlenACittMélrbs;vaRbePT longlong

PP

Page 20: chapter 3 Java at rupp cambodia

2020

static float min(float static float min(float xx, float , float yy)) eGaytMélGb,brmaéneGaytMélGb,brmaén xx nignig yy

static float signum(float static float signum(float argarg))

eGaytMélCacMnYnmYytageGay eGaytMélCacMnYnmYytageGay sBaØaénsBaØaén argarg : : vaeGaytMélvaeGaytMél –1.0 –1.0 kalNakalNa argarg

mantMélGviC¢man nigeGaytMélmantMélGviC¢man nigeGaytMél 0.00.0

kalNakalNa argarg mantMélsUnü ehIyvaeGaytMélmantMélsUnü ehIyvaeGaytMél

1.01.0 kalNakalNa argarg mantMélviC¢manRbePTmantMélviC¢manRbePT floatfloat..static double signum(double static double signum(double argarg))

eGaytMélCacMnYnmYytag eGaytMélCacMnYnmYytag eGaysBaØaéneGaysBaØaén arg : arg : vaeGaytMélvaeGaytMél –1.0–1.0 kalNakalNa argarg

mantMél GviC¢mannigeGaytMélmantMél GviC¢mannigeGaytMél 0.00.0

kalNakalNa argarg mantMélsUnü ehIyva eGaytMélmantMélsUnü ehIyva eGaytMél

1.01.0 kalNakalNa argarg mantMélviC¢manRbePTmantMélviC¢manRbePT floatfloat..

Page 21: chapter 3 Java at rupp cambodia

2121

static double exp(double static double exp(double argarg)) eGaytMélCaeGaytMélCa ee

sV½yKuNsV½yKuN argarg

static double log(double static double log(double argarg)) eGaytMélCaLÚkarIteGaytMélCaLÚkarIt ee

énén argarg

static double log10(double static double log10(double argarg)) eGaytMélCaLÚkarIt eGaytMélCaLÚkarIt eKaldb;én eKaldb;én argarg

static double pow(double static double pow(double xx, double , double yy)) eGayeGay tMélCatMélCa

xx sV½yKuNsV½yKuN yystatic double sqrt(double static double sqrt(double argarg))

eGaytMélCabJskaeréneGaytMélCabJskaerén argarg

static double cbrt(double static double cbrt(double argarg)) eGaytMélCabJseGaytMélCabJs cubecube én én argarg

PP

Page 22: chapter 3 Java at rupp cambodia

2222

static double hypot(double static double hypot(double arg1arg1, double , double arg2arg2)) eGay eGay tMélCaGIub:UetnusénRtIekaNEkgtamtMélCaGIub:UetnusénRtIekaNEkgtamRTwsIþbTBItahÁ½rRTwsIþbTBItahÁ½r

static double sin(double static double sin(double argarg)) eGaytMélsIunusénmMuEdl eGaytMélsIunusénmMuEdl kMNt;edaykMNt;eday argarg KitCara:düg;KitCara:düg;

static double cos(double static double cos(double argarg)) eGaytMélkUsIunusénmMuEdl eGaytMélkUsIunusénmMuEdl kMNt;edaykMNt;eday argarg KitCara:düg;KitCara:düg;

static double tan(double static double tan(double argarg)) eGaytMéltg;süg;énmMuEdl eGaytMéltg;süg;énmMuEdl kMNt;edaykMNt;eday argarg KitCara:düg;KitCara:düg;

static double asin(double static double asin(double argarg)) eGaytMélCamMuEdlsIunus eGaytMélCamMuEdlsIunus rbs;va)ankMNt;edayrbs;va)ankMNt;eday argarg

PP

Page 23: chapter 3 Java at rupp cambodia

2323

static double acos(double static double acos(double argarg)) eGaytMélCamMuEdl eGaytMélCamMuEdl kUsIunusrbs;va)ankMNt;edaykUsIunusrbs;va)ankMNt;eday argarg

static double atan(double static double atan(double argarg)) eGaytMélCamMuEdl eGaytMélCamMuEdl tg;süg;rbs;va)ankMNt;edaytg;süg;rbs;va)ankMNt;eday argarg

static double atan2(double static double atan2(double xx, double , double yy)) eGay eGay tMélCamMuEdltg;süg;rbs;vaesµInwtMélCamMuEdltg;süg;rbs;vaesµInwgg x/y x/y

static double random()static double random() eGaytMélmYymintamlMdab; eGaytMélmYymintamlMdab; lMeday. tMélrbs;vaKWcenøaHlMeday. tMélrbs;vaKWcenøaH 0 0 nignig 11.. PP

Page 24: chapter 3 Java at rupp cambodia

2424

static double toRadians(double static double toRadians(double angleangle)) eGay eGay tMélmYyEdlbMElgBIdWeRkeTACatMélmYyEdlbMElgBIdWeRkeTACara:düg;.ra:düg;.

static double toDegrees(double static double toDegrees(double radiansradians)) eGay eGay tMélmYyEdlbMElgBIra:düg;mkCadtMélmYyEdlbMElgBIra:düg;mkCadWeRkWeRk

kmµviFIxageRkamenHbgðajnUvkkmµviFIxageRkamenHbgðajnUvkareRbIareRbI toRadians() toRadians() nignig toDegrees() toDegrees()..PP

Page 25: chapter 3 Java at rupp cambodia

2525

9> 9> rebreboobebeRbRbII printfprintf()() method methodedaysaredaysar printf() printf() enAkñúgPasaenAkñúgPasa C C manlkçN³gay manlkçN³gay RsYleRbInigmankarniymeRcIn RsYleRbInigmankarniymeRcIn ehtuenHehtuenH Java 1.5 Java 1.5 k¾)an bBa©ÚlnUvk¾)an bBa©ÚlnUv printf() methods printf() methods sMrab;eRbIbgðajTMrg;sMrab;eRbIbgðajTMrg; output output mkelIeGRkg;dUceTAnwgPasamkelIeGRkg;dUceTAnwgPasa C C Edr. vamanEdr. vaman conversion specifiers conversion specifiers mYycMnYndUcxageRkam ³mYycMnYndUcxageRkam ³

Page 26: chapter 3 Java at rupp cambodia

2626

Page 27: chapter 3 Java at rupp cambodia

2727

]]TahrN_TahrN_ ³ ³ eKmantMélelxTsPaK eKmantMélelxTsPaK KWKW 3.14159 3.14159 ehIy ehIy cg;bgðajelxenaHEdlenAxageRkacg;bgðajelxenaHEdlenAxageRkayek,ósrbs;vaEtBIrxÞg; yek,ósrbs;vaEtBIrxÞg; elxb:ueNÑaH eKGacsresr ³elxb:ueNÑaH eKGacsresr ³ double pi = 3.14159;double pi = 3.14159;

System.out.printf("%.2f\n",pi);System.out.printf("%.2f\n",pi);

krNIbgðajtMélelxeRkamTMrg; krNIbgðajtMélelxeRkamTMrg; scientific notationscientific notation³³

double val = 123456.7890;double val = 123456.7890; System.out.printf("%.2g\n",val);System.out.printf("%.2g\n",val); System.out.printf("%,f\n",val);System.out.printf("%,f\n",val);

Page 28: chapter 3 Java at rupp cambodia

2828

10>10>karekareRbRbII Methods Methods mYmYycMycMnnYnrbs;Ynrbs; Scanner classScanner classedIm,IGantMélbBa©ÚlCacMnYnelx edIm,IGantMélbBa©ÚlCacMnYnelx tYGkSr mYyBakü b¤ tYGkSr mYyBakü b¤ GkSrmYyXøatamry³GkSrmYyXøatamry³ keyboard keyboard eKGaceRbIeKGaceRbI methods methods mYycMnYnrbs;mYycMnYnrbs; Scanner classScanner class.. Scanner class Scanner class )an pÞúkenAkñúg)an pÞúkenAkñúg package package mYyeQµaHmYyeQµaH java.util java.util.. methods methods rbs;vamaneQµaHdUcxageRkam ³rbs;vamaneQµaHdUcxageRkam ³boolean nextBoolean()boolean nextBoolean() GantMélRbePTGantMélRbePT boolean booleanbyte nextByte()byte nextByte() GantMélRbePTGantMélRbePT byte byte

Page 29: chapter 3 Java at rupp cambodia

2929

double nextDouble()double nextDouble() GantMélRbePTGantMélRbePT double double float nextFloat()float nextFloat() GantMélRbePTGantMélRbePT float float int nextInt()int nextInt() GantMélRbePTGantMélRbePT int int String next ()String next () GantMélRbePTGantMélRbePT string string ¬mYyBakü¦¬mYyBakü¦

String nextLine ()String nextLine () GantMélRbePTGantMélRbePT string string ¬mYyXøa¦¬mYyXøa¦

long nextLong()long nextLong() GantMélRbePTGantMélRbePT long long short nextShort()short nextShort() GantMélRbePTGantMélRbePT short short char findInLine(char findInLine(““..””).charAt(0)).charAt(0) GantMélRbePTGantMélRbePT

charchar

PP

PP

Page 30: chapter 3 Java at rupp cambodia

3030

edIm,IkarBarnUvkarGanbBa©ÚlRbePTTiedIm,IkarBarnUvkarGanbBa©ÚlRbePTTinñn½yeGay)an RtwmRtUvehIyeCosvagnñn½yeGay)an RtwmRtUvehIyeCosvag error error enaHeKGaceRbIenaHeKGaceRbI method method³ ³

boolean hasNextBoolean()boolean hasNextBoolean() eGaytMéleGaytMél true true ebIsinCa ebIsinCa tMélEdlRtUvbBa©ÚlenAbnÞab;CaRbePTtMélEdlRtUvbBa©ÚlenAbnÞab;CaRbePT booleanboolean

boolean hasNextByte()boolean hasNextByte() eGaytMéleGaytMél true true ebIsinCa ebIsinCa tMélEdlRtUvbBa©ÚlenAbnÞab;CaRbePTtMélEdlRtUvbBa©ÚlenAbnÞab;CaRbePT bytebyte

boolean hasNextDouble()boolean hasNextDouble() eGaytMéleGaytMél true true ebIsin ebIsin CatMélEdlRtUvbBa©ÚlenAbnÞab;CaRbeCatMélEdlRtUvbBa©ÚlenAbnÞab;CaRbePTPT double double

Page 31: chapter 3 Java at rupp cambodia

3131

boolean hasNextFloat()boolean hasNextFloat() eGaytMéleGaytMél true true ebIsinCa ebIsinCa tMélEdlRtUvbBa©ÚlenAbnÞab;CatMélEdlRtUvbBa©ÚlenAbnÞab;CaRbePTRbePT float float..

boolean hasNextInt()boolean hasNextInt() eGaytMéleGaytMél true true ebIsinCa ebIsinCa tMélEdlRtUvbBa©ÚlenAbnÞab;CatMélEdlRtUvbBa©ÚlenAbnÞab;CaRbePTRbePT int int ..

boolean hasNextLong()boolean hasNextLong() eGaytMéleGaytMél true true ebIsinCa ebIsinCa tMélEdlRtUvbBa©ÚlenAbnÞab;CatMélEdlRtUvbBa©ÚlenAbnÞab;CaRbePTRbePT long long ..

Page 32: chapter 3 Java at rupp cambodia

3232

boolean hasNextShort()boolean hasNextShort() eGaytMéleGaytMél true true ebIsinCa ebIsinCa tMélEdlRtUvbBa©ÚlenAbnÞab;CaRtMélEdlRtUvbBa©ÚlenAbnÞab;CaRbePTbePT shortshort..

boolean hasNext ()boolean hasNext () eGaytMéleGaytMél truetrue ebIsinCaebIsinCa tMélEdlRtUvbBa©ÚlenAbnÞab;CatMélEdlRtUvbBa©ÚlenAbnÞab;CaGkSrmYyBaküGkSrmYyBakü (word)(word) ..

boolean hasNextLine ()boolean hasNextLine () eGaytMéleGaytMél truetrue ebIsinCa ebIsinCa tMélEdlRtUvbBa©ÚlenAbnÞab;CatMélEdlRtUvbBa©ÚlenAbnÞab;CaGkSrmYybnÞat;GkSrmYybnÞat; (line)(line)..

Page 33: chapter 3 Java at rupp cambodia

3333

1 - etIsBaØaNnBVnþelx % eRbIsMrab;eFVIGVI? ehIyvaGac eRbI)anCamYynwgRbePTTinñn½yNaxøH?

2 - etIeKGaceRbI shift operators sMrab;KuN b¤EckcMnYnKt; mYyeTAnwgelxBIr)anEdrb¤eT?

3 - etIRbePTTinñn½yNaxøHEdlsBaØaNnBVnþelxeKalBIr (bitwise operators) GaceRbI)an?

sMNYr niglMhat;sMNYr niglMhat;

Page 34: chapter 3 Java at rupp cambodia

3434

4 - cUrsresr code xageRkamenHeTACaTMrg;énkareRbI ?

operator ³ if (x < 0) y = 10; else y = 20;

5 - sBaØa & enAkñúg code xageRkamenH etIeKeRbI bitwise operator b¤ logical operator? eRBaHGVI?

boolean a, b; // ... if(a & b) ...

6 - cUrbgðajQñab;nig ( AND ) GackarBarmineGayEckcMnYnmYy eTAnwgsUnü)an.

Page 35: chapter 3 Java at rupp cambodia

3535

7 - etI code xageRkamenHeGaylT§plGVI? System.out.printf("%(d \n", -23); System.out.printf("%(d \n", -23); System.out.printf("**%2d** \n", 0);System.out.printf("**%2d** \n", 0);System.out.printf("%.4s \n", "lengthy");System.out.printf("%.4s \n", "lengthy");

8 - cUrsresrkmµviFImYyEdlGaceGayeKbBa©ÚltMélCaGtþelx eQµaH ePT BinÞúKNit rUb KImI kMuBüÚT½rrbs;nisSitmñak;BI keyboard rYcbgðajBt’manmkelIeGRkg;tamTMrg;xageRkam ³Id Name Sex Total Scores Average Scores