CMBUkTI4 XøaepÞógpÞat;lkçx½NÐ 3

Size: px
Start display at page:

Download "CMBUkTI4 XøaepÞógpÞat;lkçx½NÐ 3"

Transcription

1 JAVA Programming ChapterIV CMBUkTI4 XøaepÞógpÞat;lkçx½NÐ 3 XøaepÞógpÞat;lkçx½NÐenAkñúgPasa Java RtUv)anerobdak;eTAtamRbePTdUcCa³ Selection, Iteration nig Jump. XøaRbePT Selection GaceGaykmμviFIrbs;eyIgeRCIsyknUvtMeNIrRbtibtþikarepSgKña edayep keli lt plénkensammyy b spabéngbaøatiþmyy. XøaRbePT Iteration GaceGaykarRbtibtþikmμviFI efviskmμpab dedl²nuvxøamyy b ercin)an mann½yfa Iteration bgá)andmenirrgvil. XøaRbePT Jump GaceGaykmμviFI rbs;eyigrbtibtþikartamlkçn³minlmdab;lmeday. 1> XøaRbePT Selection én Java(Selection statement): Java pþl;nuvxøarbept selection cmnynbirkw³ if nig switch. XøaTaMgenHGaceGayeyIgepÞógpÞat;tMenIr karénkmμvifi Ep kelilkçx½nð EdlGacdwg)aneBldMeNIrkar. 1>1 Xøa If (If statement) Xøa If KWEckecjeTAtamlkçx½NÐrbs; Java. vagacerbismrab;namtmenirkarkmμvifi tampøúvbirepsg Kña. enhcatmrg;rbs;xøa If ³ if (condition) statement; else statement; kñúgenah statement nimyy² GacCaXøaeTalmYy b ercinxøa Edldak;kñúgsBaØa {. condition CatMélelxNa EdleGaytMélCa boolean. else CaXøaEdlGacCMerIl. cursegátxøakñúg]tahrn_xagerkam³ int a, b; //... if ( a < b ) a = 0; else b = 0; 1>1>1 Xøa If enakñug If myyetot (If in If) Xøa if myyenakñúg if myyetot KWCaXøa if myyedlcaplén if b else myy. kalna eyigdak; if myyenakñúg if myyetotenah bbaðasmxan;edlrtuvcamenah KW Xøa else myy Canic CakalsMedAeTArk if EdlCitbMput ehiysßitkñúg block duckña. enhca]tahrn_myy³ if ( i==10 ){ if ( j < 20 ) a = b; if ( k > 100 ) c = d; else else a = c; //this if is //associated with this else a = d; //this else refers to if ( i==10 ) Prepared by: Mr. Rin Ratha Cambodian University for Specialties

2 JAVA Programming ChapterIV 1>1>2 lmdab;fñak; if-else-if (If-else-If) karbegáitkmμvifituetamyy EdlmanmUldæanenAelIlMdab;tKñaénXøa if myyenakñúg if myy etot KWCalMdab; if-else-if. vamantmrg;ducxagerkam³ if (condition) statement; else if (condition) statement; else if (condition) else statement;. statement; enhcakmμvifimyyedlerbilmdab;fñak; if-else-if edim,ikmnt;faetiexnasßitenakñúgrduvna³ //demostrates if-else-if statements; class IfElse{ int month = 4; String season; if ( month ==12 month == 1 month == 2 ) season = "Winter"; else if ( month == 3 month == 4 month == 5 ) season = "Spring"; else if ( month ==6 month == 7 month == 8) season = "Summer"; else if ( month == 9 month == 10 month == 11) season = "Autumn"; else season = "Bogus Month"; System.out.println("April is in the " + season + "."); 1>2 Xøa switch (Switch statement) Xøa switch KWCaXøaEdlEckecjCaeRcInpøÚvenAkñúg Java. vapþl;mefüa)aygayrsylmyy edim,i bba ÚnkarRbtibtþieTAeGayEpñkepSgKña én code edayep kelitmélénkensamelx. vifienhpþl;nuvmefüa)ay myyetotedll CaXøa if-else-if. enhcatmrg;tuetaénxøa switch³ switch (expression){ case value1: //statement sequence break; case value2: //statement sequence break; Prepared by: Rin Ratha Cambodian University for Specialties

3 JAVA Programming ChapterIV. case valuen: //statement sequence break; default: //default statement sequence kñúgenah expression RtUvEtCaRbePT byte, short, int b char ehiytmélnimyy²edl)ankmnt;enakñúgxøa case nimyy² RtUvEtCaRbePTRtUvKñanwg expression. tmélrbs; case nimyy² RtUvEtCacMnYnefr minemncagbaøatþi. tmélrbs; case duckña KWminGnuBaØatþieGayeRbIeT. Xøa break RtUv)aneRbIenAkñúg switch edim,ibba b;lmdab;xaømyy. lkçn³enh GaceGaydMenIrkarecj putmkerka én switch. kmμvifixagerkamenhca]tahrn_tucmyybikarerbixøa switch³ //simple example of switch statement class SimpleSwitch{ for ( int i = 0; i<6; i++ ) switch ( i ){ case 0: System.out.println(" i is zero"); break; case 1: System.out.println(" i is one"); break; case 2: System.out.println(" i is two"); break; case 3: System.out.println(" i is three"); break; default: System.out.println(" i is greater than 3"); break; Xøa break manlkçn³cmeris erbik¾)an minerbik¾)an. ebieyiglub break karrbtibtþinwgbnþetakan; case bnþab;. CYnkalvaRtUvkarman case CaeRcInedaymineRbIXøa break enacenøah case TaMgenaH. ]TahrN_ cursegátkmμvifixagerkam³ // In a switch, break statements are optional. class MissingBreak{ for ( int i = 0; i<12; i++ ){ switch ( i ){ case 0: case 1: case 2: case 3: case 4: System.out.println("i is less than 5"); break; Prepared by: Mr. Rin Ratha Cambodian University for Specialties

4 JAVA Programming ChapterIV case 5: case 6: case 7: case 8: case 9: default: System.out.println("i is less than 10"); break; System.out.println("i is 10 or more"); tmenirkarqøgkat;cuhmkerkamtam case nimyy² rhutdl;cyb break b rhuldl;cugbba b;én switch. kmμvifixagerkamenhcakmrumyy EdlbgðajeGayeXIjc,as;BIkarGnuvtþn_manRbsiT ipabercin. eyigeliyk kmμvifielikmunmksresreligvij duecñheyiggacsegátbikarerbiva³ //an improved version of the season program. class ImprovedSeason{ int month = 4; String season; switch ( month ){ case 12: case 1: case 2: season = "winter"; break; case 3: case 4: case 5: season = "spring"; break; case 6: case 7: case 8: season = "summer"; break; case 9: case 10: case 11: season = "autumn"; break; default: season = "bogus month"; System.out.println("April is in the " + season + "."); eyiggacerbi switch CaEpñkénlMdab;Xøarbs; switch enaxagerka)an. lkçn³enhehafa switch myyenakñúg switch myyetot (nested switch). edayxøa switch kmnt;nuv block erogxøün efviegayvaminman karb:htgáickña rvagtmélefrrbs; case ena switch xagkñúg ehiynig switch xagerka. ]TahrN_ sresrxøa xagerkamenhbitcartwmrtuv³ Prepared by: Mr. Rin Rath Cambodian University for Specialties

5 JAVA Programming ChapterIV switch ( count ){ case 1: case 2: switch ( target ){ case 0:.. case 1: System.out.println ( target is zero ); break; System.out.println ( target is one ); break; 2> XøaRbePT Iteration én Java(Iteration statement): XøaRbePT Iteration enakñúg Java KW for, while nig do-while. XøaTaMgenHbegáIteLIgnUvGVIEdleyIg ehacatuetafa dmenirrgvil (loop). 2>1 dmenirrgvil while (While loop statement) dmenirrgvil while KWCaXøadMenIrbgVilsMxan;bMputrbs; Java. varbrbitþdedl²nuvxøamyy b block myy enaebledlkensamlkçnðbit. enhcatmrg;rbs;va³ while ( condition ){ //body of loop enakñúgenah condition GacCakenSam boolean NamYy. tyéntmenirrgvil nwgrbtibtþirhut ebikensamlkçnð Bit. enaebledl condition minbit enahtmenirepþógpþat; nwgqøgetabnþat;bnþab;én code EdlenACab;nwg tmenir rgvil. ebimanxøaetmyyb:uenñah enaerkamlkçnðedlrtuvepþógpþat;dedl²enah ekmincam)ac;erbisbaøa { et. ]TahrN_enHCargVil while Edlrab;elxfyBI 10 mk ehiye)ahecjnuvbakü tick cmnyn 10 bnþat;. //demonstrate the while loop class WhileLoop{ int n = 10; while ( n > 0 ){ System.out.println("tick " + n); n--; edaysaret while rgvaytmélkñúgkensamlkçnðenaxagelitmenirrgvil tyéntmenirrgvil nwgmin RbtibtþieLIy RbsinebIlkçNÐminBit enaeblcab;epþim. ]TahrN_ code enaxagerkamenh karerbi println() minrbtibtþital;etesah. Prepared by: Mr. Rin Ratha Cambodian University for Specialties

6 JAVA Programming ChapterIV int a = 10, b = 20; while ( a > b ) System.out.println( This will not be displayed ); tyrbs; while b tmenirrgvilepsgetotrbs; Java GacsßitenATeT. enhmkbivacaxøatet CaXøaEdlmanEtsBaØa ; b:uenñah EdlCaXøaRtwmRtUv enakñúgpasa Java. ]TahrN_ cursegátkmμvifixag erkam³ //The target of a loop can be empty class NoBody{ public sattic void main(string Args[]){ int i, j; i= 100; j= 200; while ( ++i < --j ); System.out.println("Midpoint is " + i); 2>2 dmenirrgvil do-while (Do-While loop statement) dmenirrgvil do-while Canic CakalRbtibtþikarkñúgtYrbs;va ya:gticmþg BIeRBaHkenSamlkçNÐ rbs;va enaxagerkaméndmenirrgvil. TMrg;TUeTArbs;vaKW³ do { //body of loop while ( condition ); enakñúgdmenirrgvil do-while Rbtibtþikarmþg² KWdMbUgtYrbs;va rycehiyetibrgvaytmélkensamlkçnð. ebisincakensamlkçnðenah Bit enahdmenirrgvilkwrbtibtþidmenirkarsarcafμimþgetot. pþúyetavij dmenirkarrtuv bba b;. RKb;dMenIrrgVilTaMgGs;rbs; Java, condition RtUvEtCakenSam boolean. kmμvifixagerkamenh Cakmμ vifielikmunedlegaylt plca tick cmnyn 10 dg EtkñúgeBlenHeyIgykvamkeRbICamYyXøa do-while vij mþg. vaegaylt plduckñanwgelikmunedr³ //Demonstrate the do-while loop class DoWhile{ int n = 10; do{ System.out.println("tick " + n); n--; while ( n > 0 ); Prepared by: Mr. Rin Ratha Cambodian University for Specialties

7 JAVA Programming ChapterIV 2>3 dmenirrgvil for (for loop statement) dmenirrgvil for KWCarcnasm<½n myymangnupabxøamg nig manlkçn³bt;ebn. enhcatmrg;tueta rbs; for³ for ( initialization; condition; iteration ){ body; enhcakmμvifierbidmenirrgvil for³ //Demonstrate the for loop class ForTick{ int n; for ( n =10 ; n > 0 ; n-- ){ System.out.println("tick " + n); 2>4 karrbkasgbaøatþienakñúgdmenirrgvil for (Declaring a variable in a for loop) GBaØatþiEdlepÞógpÞat;dMenIrrgVil for KWRtUvkarsMrab;EteKalbMNgénXøa for b:uenñah ehiymin GaceRbIenAkEnøgepSgeTot)aneLIy. enakñúgkrnienh vagacegayeyigrbkasgbaøatþienaxagkñúg for Epñk kmnt;tméldmbugrbs; for. ]TahrN_xageRkamenH CakmμviFIelIkmunEdl)anelIkeLIg duecñhgbaøatþiepþógpþat; dmenirrgvil n nwgrtuvrbkascarbept int ducenakñúgxøa for Edr. //Demonstrate a loop control variable inside for loop class VarLoop{ for ( int n =10 ; n > 0 ; n-- ){ System.out.println("tick " + n); kalnaeyigrbkasgbaøatþimyyenakñúgdmenirrgvil for eyigrtuvdwgfa vamancmnucsmxan;myy KW TMhMén GBaØatþienaHbBa b; enaeblxøa for bba b;edr. enhmann½yfa TMhMrbs;GBaØatþi RtUv)ankMritedayXøa for. kalnagbaøatþiepþógpþat;dmenirrgvil minrtuvkarenakenøgepsgetoenah GñksresrkmμviFIRbkasva ena kñúg for. ]TahrN_xageRkamenH CakmμviFItUcmYy EdlepÞógpÞat;cMnYnbzm. curkt;smkal;fa GBaØatþiepÞógpÞat; dmenirrgvil i RtUvRbkasenAkñúg for erbahvaminrtuvkarerbienakenøgepsgetot. Prepared by: Mr. Rin Ratha Cambodian University for Specialties

8 JAVA Programming ChapterIV //Test for primes. class FindPrime{ int num; boolean isprime = true; num = 14; for ( int i =2; i < num / 2; i++ ){ if ( num % i == 0 ){ isprime = false; break; if ( isprime ) System.out.println("Prime"); else System.out.println("Not Prime"); 2>5 karerbisbaøaek,ós (Using comma) edim,iegaygbaøatþibir b ercinepþógpþat;dmenirrgvil for, Java GaceGayeyIg bba ÚlXøaeRcIn enartg;titamgkmnt;tméldmbug nig TItaMgeFVIskμPaBdEdl²rbs; for. XøamYyenAdac;BIXøamYyeTot edaysbaøa ek,ós. tamry³karerbisbaøaek,ós dmenirrgvil for elikmun GaceGayeyIgsresr code manrbsit i PaBCag duc)anbgðajxagerkamenh³ //Using the comma class Comma{ public static void main(string Args[])[ int a, b; for ( a =1, b =4; a < b; a++, b--){ System.out.println("a = " + a); System.out.println("b = " + b); 2>6 dmenirrgvilmyyenakñúgdmenirrgvilmyyetot (for in for) duckñúgpasad¾étetotedr Java GaceGaydMenIrrgVil sßitkñúgdmenirrgvilmyyeto. xagerkamenh CakmμviFImYy erbi for myyenakñúg for myyetot. Prepared by: Mr. Rin Ratha Cambodian University for Specialties

9 JAVA Programming ChapterIV //loop may be nested class Nested{ int i, j; for ( i = 0 ; i < 10 ; i++ ){ for ( j = i ; j < 10 ; j++ ) System.out.println("."); System.out.println(); 3> XøaRbePT Jump(Jump statement): Java pþl;nuvxøarbept Jump cmnynbikw³ break, continue nig return. 3>1 karerbi break (Using break) enakñúg Java Xøa break mankarerbi 3 ya:g. TImYy duceyig)andwgehiyfa vaerbismrab; bba b; lmdab;enakñúgxøa switch. TIBIr vagacerbismrab;cakecjbidmenirrgvil. TIbI vartu)anerbicatmrg; goto. enaebl enh eyignwgbnül;bikarerbir)as;xøatamgbircugerkayenh. 3>2 karerbi break smrab;cakecjbidmenirrgvil(using break to break a loop) tamry³karerbixøa break eyiggacbgçmegayvabba b;pøam² nuvdmenirkarbgvil)an edayrmlg kensamlkçnð nig code EdlenAsl;kñúgtYén loo. kalnaxøa break myy CYbRbT³enAkñúg loop dmenirrbs; loop RtUv)anbBa b; ehiykmμvifiepþógpþat;nwgcab;epþimenaxøabnþab;. xagerkamca]tahrn_³ //Using break to exit a loop class BreakLoop{ for ( int i = 0; i < 100 ; i++ ) { if ( i == 10 ) break; //terminate loop if i = 10 System.out.println("i: " + i); System.out.println("Loop completed"); Xøa break GaceRbICamYyXøa loop rbs; Java. ]TahrN_xageRkamenHCakmμviFIelIkmunEdl)an sresrbgðajbikarerbidmenirrgvil while. lt plénkmμvifienh k¾ducetanwgkmμvifielikmunedr³ Prepared by: Mr. Rin Ratha Cambodian University for Specialties

10 JAVA Programming ChapterIV //Using break to exit a while loop class BreakLoop2{ int i = 0; while ( i < 100 ) { if ( i == 100 ) break; System.ou.println("i: " + i ); i++; System.out.println("Loop complete"); kalnaerbienakñúgdmenirrgvilercincan;enah Xøa break nwggaccakecjetdmenirrgvilnaedlenakñúg bmput. ]TahrN_³ //Using break with nested loop class BreakLoop3{ for ( int i = 0; i < 3 ; i++ ){ System.out.println("Pass i " + i + ":" ); for ( int j = 0; j < 100 ; j++ ){ if ( j == 10 ) break; System.out.println( j + " " ); System.out.println(); System.out.println("Loop complete"); 3>3 karerbi break ducnwgtmrg; goto(using break as a goto) Xøa break GaceRbIedayxøÜnva edim,ipþl;nuvtmrg; goto. TMrg;TUeTAénXøa break )anbgðajduc xagerkam³ break label; kñúgenah label KWCaeQμaHénsBaØasMKal; EdleRbIsMrab;sMKal; block én code. enaebltmrg;én break enh Rbtibtþikar enahkarepþógpþat;kwsmedaetarkeqμah block én code. Xøa break EdlmaneQμaHRtUvdakenAkñúg block én code. enhmann½yfa eyiggacerbixøa break EdlmaneQμaHsMrab;cakecjBIsMnuM block. b:uenþeyig mingacerbixøa break edim,irk block én code EdlminmanGmXøa break enaheliy. edim,idak;eqμahegay block myy eyigdak;eqμahsbaøasmkal;enaxagedim block nig sbaøa : enabierkay. kmμvifixagerkamenh bgðajbi block bican;edl block nimyy² maneqμaherog²xøün. Xøa break efviegaykarrbtibtþielatetamux hystibba b;én block EdlmaneQμaH second edayrmlgxøa println() BIr. Prepared by: Mr. Rin Ratha Cambodian University for Specialties

11 JAVA Programming ChapterIV //Using a break as a civilized form of goto class Break{ boolean t = true; first: { second: { third: { System.out.println("Before the break."); if ( t ) break second; System.out.println("This wont execute"); System.out.println("This wont execute"); System.out.println("This is after second block"); karerbixøa break CamYyeQμaHsBaØasMKal;eRcInCageKenaH KW edim,icakecjbidmenirrgvilmyy enakñúg dmenirrgvilmyyetot. cursegátkmμvifixagerkamenh³ //Using break to exit from nested loop class BreakLoop4{ public static void main(string Ags[]){ outer: for ( int i = 0 ; i < 3 ; i++ ){ System.out.println("Pass " + i ); for ( int j = 0 ; j < 100 ; j++ ){ if ( j == 10 ) break outer; \\exit both loops System.out.println( j + " "); System.out.pirntln("This will not print"); System.out.println("Loops complete"); duceyig)anexijrsab;ehiyfa enaebldmenirrgvilxagkñúg bmebkecjetakan;dmenirrgvilxagerkaenah dmenirtamgbirrtuv)anbba b;. RtUvcaMTukfa eyigmingacbmebkecjetakan;eqμahsbaøanamyy Edlmin)ankMnt; smrab; block enaheliy. xtahrn_xagerkamenh minrtwmrtuv ehiyminefvikarbmebkecjeliy³ class BreakErr{ one: for ( int i = 0 ; i < 3 ; i++ ){ System.out.println("Pass " + i); for ( int j = 0 ; j < 100 ; j++ ){ if ( j == 10 ) break one; //Wrong System.out.println( j + " " ); Prepared by: Mr. Rin Rtha Cambodian University for Specialties

12 JAVA Programming ChapterIV 4> karerbi Continue(Using a Continue statement): CYnkalvamanRbeyaCn_Edr kñúgkarbgçmegayqab;efviskmμpabdedl² rbs;dmenirrgvil. )ann½yfa eyigcg;bnþdmenirkarrgvil b:uenþbbaäb;dmenirkar code EdlenAesssl; kñúgtyrbs;va cmebahkarefviskmμpab dedl²enh. lkçn³enhkwca goto EdlrMlgtYéndMenIrrgVil etakan;cugerkayéndmenirrgvil. Xøa continue efiv skmμpabebbenh. enhcakmru EdleRbI continue bnþalegaybircmnyn e)ahenaelibnþat;nimyy². //Demonstrate Continue class Continue{ for ( int i = 0 ; i < 10 ; i++ ){ System.out.println( i + " " ); if ( i % 2 == 0 ) continue; System.out.pirntln(" "); duckñanwg break Edr continue GackMnt;nUvsBaØasMKal;mYy edim,ir)ab;nuvdmenirrgvilnaedlrtuv bnþskmμpab. enhcakmμvifimyy EdleRbI continue edim,ie)ahecjnuvtaragmyy ragrtiekanbi 0 dl; 9. //Using continue with label class ContinueLabel{ outer: for ( int i = 0 ; i < 10 ; i++ ){ for ( int j = 0 ; j < 10 ; j++ ){ if ( j > i ){ System.out.println(); continue outer; System.out.println( " " + (i * j) ); System.out.println(); 5> karerbi return(using a return statement): Xøa return RtUv)aneRbIsMrab;eGaytMélBI method myyedayc,as;las;. )ann½yfa vaepþógpþat; edim,ibenþretaegay GñkehA method enah. vartuv)ancat;culcaxøarbept Jump. enaeblnak¾edayenakñúg method myy/ Xøa return GaceRbIsMrab;eFVIeGaykarRbtibtþi EbkecjeTArk GñkehA method enah. duecñh Xøa return bba b; method Pøam² eblvartuv)andmenirkarenakñúg method enah. ]TahrN_xageRkamenHbgðajBIcMnucTaMgenH. kñúgenh return efviegaykarrbtibtþiviletarkrbb½n dmenirkar rbs; Java eblvaeha main. Prepared by: Mr. Rin Ratha Cambodian University for Specialties

13 JAVA Programming ChapterIV //Demonstrate return class Return{ boolean t = true; System.out.println("Before the return"); if ( t ) return; // return to caller System.out.println("This wont execute"); 5 Prepared by: Mr. Rin Ratha Cambodian University for Specialties

CMBUkTI3 sbaøannbvnþelx 3

CMBUkTI3 sbaøannbvnþelx 3 JAVA Programming - 21 - ChapterIII CMBUkTI3 sbaøannbvnþelx 3 1> sbaøannbvnþelxknit(arithmetic operators): sbaøannbvnþelxknit RtUv)aneRbIenAkñúgkenSamelxKNitvITüa EdldUceTAnwgkareRbIenAkñúg BiCKNitEdr.

More information

CMBUkTI2 RbePTTinñn½y/ GBaØatþi/ nig Arrays 3

CMBUkTI2 RbePTTinñn½y/ GBaØatþi/ nig Arrays 3 JAVA Programming - 6 - ChapterII CMBUkTI2 RbePTTinñn½y/ GBaØatþi/ nig Arrays 3 Java KWCaPasamanlkçN³kMNt;RbePTTinñn½yc,as;las;. ktþaenhehiykwca EpñkmYyrbs; Java EdleFVIeGaymanPaBrwgmaM nigmansuvtßipab.

More information

10/30/2010. Introduction to Control Statements. The if and if-else Statements (cont.) Principal forms: JAVA CONTROL STATEMENTS SELECTION STATEMENTS

10/30/2010. Introduction to Control Statements. The if and if-else Statements (cont.) Principal forms: JAVA CONTROL STATEMENTS SELECTION STATEMENTS JAVA CONTROL STATEMENTS Introduction to Control statements are used in programming languages to cause the flow of control to advance and branch based on changes to the state of a program. In Java, control

More information

ANNAMACHARYA INSTITUTE OF TECHNOLOGY AND SCIENCES: : TIRUPATI

ANNAMACHARYA INSTITUTE OF TECHNOLOGY AND SCIENCES: : TIRUPATI ANNAMACHARYA INSTITUTE OF TECHNOLOGY AND SCIENCES: : TIRUPATI Venkatapuram(Village),Renigunta(Mandal),Tirupati,Chitoor District, Andhra Pradesh-517520. DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING NAME

More information

Day 2 : Intermediate Concepts 1 Examples

Day 2 : Intermediate Concepts 1 Examples Example1 Day 2 : Intermediate Concepts 1 Examples public class Example1 public static void main(string[] args) int a= 5, b = 10, c = 15, d= 20; Assignment int x = a++; a is assigned to x and then increment

More information

Example: Monte Carlo Simulation 1

Example: Monte Carlo Simulation 1 Example: Monte Carlo Simulation 1 Write a program which conducts a Monte Carlo simulation to estimate π. 1 See https://en.wikipedia.org/wiki/monte_carlo_method. Zheng-Liang Lu Java Programming 133 / 149

More information

CompSci 125 Lecture 11

CompSci 125 Lecture 11 CompSci 125 Lecture 11 switch case The? conditional operator do while for Announcements hw5 Due 10/4 p2 Due 10/5 switch case! The switch case Statement Consider a simple four-function calculator 16 buttons:

More information

Content. I. Definition RIS. II. How to Install RIS Service? III. Requirement RIS Service. IV. Install the Remote Installation Service

Content. I. Definition RIS. II. How to Install RIS Service? III. Requirement RIS Service. IV. Install the Remote Installation Service Content I. Definition RIS - etigvietaca RIS?... II. How to Install RIS Service? - RIS RtUv)antMeLIgkñúgeKalbMNgedIm,IGVI?... III. Requirement RIS Service - kartmelig RIS cam)ac;rtuvmangvixøh?... IV. Install

More information

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to define and invoke void and return java methods

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to define and invoke void and return java methods Islamic University of Gaza Faculty of Engineering Computer Engineering Dept. Computer Programming Lab (ECOM 2114) ABSTRACT In this Lab you will learn to define and invoke void and return java methods JAVA

More information

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade; Control Statements Control Statements All programs could be written in terms of only one of three control structures: Sequence Structure Selection Structure Repetition Structure Sequence structure The

More information

School of Computer Science CPS109 Course Notes 6 Alexander Ferworn Updated Fall 15. CPS109 Course Notes 6. Alexander Ferworn

School of Computer Science CPS109 Course Notes 6 Alexander Ferworn Updated Fall 15. CPS109 Course Notes 6. Alexander Ferworn CPS109 Course Notes 6 Alexander Ferworn Unrelated Facts Worth Remembering Use metaphors to understand issues and explain them to others. Look up what metaphor means. Table of Contents Contents 1 ITERATION...

More information

Example. Write a program which sums two random integers and lets the user repeatedly enter a new answer until it is correct.

Example. Write a program which sums two random integers and lets the user repeatedly enter a new answer until it is correct. Example Write a program which sums two random integers and lets the user repeatedly enter a new answer until it is correct. 1... 2 Scanner input = new Scanner(System.in); 3 int x = (int) (Math.random()

More information

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls. Jump Statements The keyword break and continue are often used in repetition structures to provide additional controls. break: the loop is terminated right after a break statement is executed. continue:

More information

CSC 1214: Object-Oriented Programming

CSC 1214: Object-Oriented Programming CSC 1214: Object-Oriented Programming J. Kizito Makerere University e-mail: jkizito@cis.mak.ac.ug www: http://serval.ug/~jona materials: http://serval.ug/~jona/materials/csc1214 e-learning environment:

More information

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution Ch 5 Arrays Multiple Choice Test 01. An array is a ** (A) data structure with one, or more, elements of the same type. (B) data structure with LIFO access. (C) data structure, which allows transfer between

More information

Following is the general form of a typical decision making structure found in most of the programming languages:

Following is the general form of a typical decision making structure found in most of the programming languages: Decision Making Decision making structures have one or more conditions to be evaluated or tested by the program, along with a statement or statements that are to be executed if the condition is determined

More information

Le L c e t c ur u e e 3 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Control Statements

Le L c e t c ur u e e 3 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Control Statements Course Name: Advanced Java Lecture 3 Topics to be covered Control Statements Introduction The control statement are used to control the flow of execution of the program. This execution order depends on

More information

Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word. Chapter 1 Introduction to Computers, Programs, and Java

Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word. Chapter 1 Introduction to Computers, Programs, and Java Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word Chapter 1 Introduction to Computers, Programs, and Java Chapter 2 Primitive Data Types and Operations Chapter 3 Selection

More information

CS111: PROGRAMMING LANGUAGE II

CS111: PROGRAMMING LANGUAGE II CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 1(c): Java Basics (II) Lecture Contents Java basics (part II) Conditions Loops Methods Conditions & Branching Conditional Statements A

More information

PROGRAMMING FUNDAMENTALS

PROGRAMMING FUNDAMENTALS PROGRAMMING FUNDAMENTALS Q1. Name any two Object Oriented Programming languages? Q2. Why is java called a platform independent language? Q3. Elaborate the java Compilation process. Q4. Why do we write

More information

CS1150 Principles of Computer Science Loops (Part II)

CS1150 Principles of Computer Science Loops (Part II) CS1150 Principles of Computer Science Loops (Part II) Yanyan Zhuang Department of Computer Science http://www.cs.uccs.edu/~yzhuang CS1150 UC. Colorado Springs Review Is this an infinite loop? Why (not)?

More information

CS171:Introduction to Computer Science II

CS171:Introduction to Computer Science II CS171:Introduction to Computer Science II Department of Mathematics and Computer Science Li Xiong 9/7/2012 1 Announcement Introductory/Eclipse Lab, Friday, Sep 7, 2-3pm (today) Hw1 to be assigned Monday,

More information

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution Ch 5 Arrays Multiple Choice 01. An array is a (A) (B) (C) (D) data structure with one, or more, elements of the same type. data structure with LIFO access. data structure, which allows transfer between

More information

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls. Jump Statements The keyword break and continue are often used in repetition structures to provide additional controls. break: the loop is terminated right after a break statement is executed. continue:

More information

Java Basic Programming Constructs

Java Basic Programming Constructs Java Basic Programming Constructs /* * This is your first java program. */ class HelloWorld{ public static void main(string[] args){ System.out.println( Hello World! ); A Closer Look at HelloWorld 2 This

More information

JAVA OPERATORS GENERAL

JAVA OPERATORS GENERAL JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

The Basic Parts of Java

The Basic Parts of Java Data Types Primitive Composite The Basic Parts of Java array (will also be covered in the lecture on Collections) Lexical Rules Expressions and operators Methods Parameter list Argument parsing An example

More information

Outline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors

Outline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors Outline Overview history and advantage how to: program, compile and execute 8 data types 3 types of errors Control statements Selection and repetition statements Classes and methods methods... 2 Oak A

More information

Chapter 4 Loops. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved.

Chapter 4 Loops. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved. Chapter 4 Loops 1 Motivations Suppose that you need to print a string (e.g., "Welcome to Java!") a hundred times. It would be tedious to have to write the following statement a hundred times: So, how do

More information

Loops. CSE 114, Computer Science 1 Stony Brook University

Loops. CSE 114, Computer Science 1 Stony Brook University Loops CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Motivation Suppose that you need to print a string (e.g., "Welcome to Java!") a user-defined times N: N?

More information

Final Examination Semester 2 / Year 2011

Final Examination Semester 2 / Year 2011 Southern College Kolej Selatan 南方学院 Final Examination Semester 2 / Year 2011 COURSE : FUNDAMENTALS OF SOFTWARE DESIGEN AND DEVELOPMENT COURSE CODE : PROG1003 TIME : 2 1/2 HOURS DEPARTMENT : COMPUTER SCIENCE

More information

Chapter 3. Selections

Chapter 3. Selections Chapter 3 Selections 1 Outline 1. Flow of Control 2. Conditional Statements 3. The if Statement 4. The if-else Statement 5. The Conditional operator 6. The Switch Statement 7. Useful Hints 2 1. Flow of

More information

Arithmetic Compound Assignment Operators

Arithmetic Compound Assignment Operators Arithmetic Compound Assignment Operators Note that these shorthand operators are not available in languages such as Matlab and R. Zheng-Liang Lu Java Programming 76 / 141 Example 1... 2 int x = 1; 3 System.out.println(x);

More information

For that purpose, java provides control structures that serve to specify what has to be done by our program, when and under which circumstances.

For that purpose, java provides control structures that serve to specify what has to be done by our program, when and under which circumstances. Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may bifurcate, repeat code or take decisions. For that purpose, java provides control structures

More information

Prof. Navrati Saxena TA: Rochak Sachan

Prof. Navrati Saxena TA: Rochak Sachan JAVA Prof. Navrati Saxena TA: Rochak Sachan Operators Operator Arithmetic Relational Logical Bitwise 1. Arithmetic Operators are used in mathematical expressions. S.N. 0 Operator Result 1. + Addition 6.

More information

CONDITIONAL EXECUTION

CONDITIONAL EXECUTION CONDITIONAL EXECUTION yes x > y? no max = x; max = y; logical AND logical OR logical NOT &&! Fundamentals of Computer Science I Outline Conditional Execution if then if then Nested if then statements Comparisons

More information

1 class Lecture3 { 2 3 "Selections" // Keywords 8 if, else, else if, switch, case, default. Zheng-Liang Lu Java Programming 89 / 137

1 class Lecture3 { 2 3 Selections // Keywords 8 if, else, else if, switch, case, default. Zheng-Liang Lu Java Programming 89 / 137 1 class Lecture3 { 2 3 "Selections" 4 5 } 6 7 // Keywords 8 if, else, else if, switch, case, default Zheng-Liang Lu Java Programming 89 / 137 Flow Controls The basic algorithm (and program) is constituted

More information

Programming Constructs Overview. Method Call System.out.print( hello ); Method Parameters

Programming Constructs Overview. Method Call System.out.print( hello ); Method Parameters Programming Constructs Overview Method calls More selection statements More assignment operators Conditional operator Unary increment and decrement operators Iteration statements Defining methods 27 October

More information

CS180. Exam 1 Review

CS180. Exam 1 Review CS180 Exam 1 Review What is the output to the following code? System.out.println("2 + 2 = " + (2 + 2)); System.out.println("2 + 2 = " + 2 + 2); What is the output to the following code? System.out.println(String.valueOf(15+20));

More information

CSCI 136 Data Structures & Advanced Programming. Lecture 3 Fall 2017 Instructors: Bill & Bill

CSCI 136 Data Structures & Advanced Programming. Lecture 3 Fall 2017 Instructors: Bill & Bill CSCI 136 Data Structures & Advanced Programming Lecture 3 Fall 2017 Instructors: Bill & Bill Administrative Details Lab today in TCL 216 (217a is available, too) Lab is due by 11pm Sunday Copy your folder

More information

Selections. CSE 114, Computer Science 1 Stony Brook University

Selections. CSE 114, Computer Science 1 Stony Brook University Selections CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Motivation If you assigned a negative value for radius in ComputeArea.java, then you don't want the

More information

CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1. Name SOLUTION

CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1. Name SOLUTION CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1 Name SOLUTION Page Points Score 2 15 3 8 4 18 5 10 6 7 7 7 8 14 9 11 10 10 Total 100 1 P age 1. Program Traces (41 points, 50 minutes)

More information

CMBUkTI1. ]bmafaenaeli Form & Report GñkeRbIR)as;begá It Action or Event egayekitmaneligenah

CMBUkTI1. ]bmafaenaeli Form & Report GñkeRbIR)as;begá It Action or Event egayekitmaneligenah CMBUkTI1 Microsoft Access Programming 2010 Macro & VBA in Microsoft Access Programing 1. Database enakñúgkarbegáit Database etaca Application myysmrab;[ekerbir)as; vamanlkçn³biesscaercin EdlGac erbiedim,icmnyydl;gñkerbir)as;kñúgkarerbi

More information

Chettinad College of Engineering & Technology/II-MCA/ MC9235 Web Programming WEB PROGRAMMING DEPARTMENT OF MCA

Chettinad College of Engineering & Technology/II-MCA/ MC9235 Web Programming WEB PROGRAMMING DEPARTMENT OF MCA WEB PROGRAMMING DEPARTMENT OF MCA Class II MCA Semester III Batch & Year B4 & 2012 Staff A.SALEEM RAJA, MCA.,M.Phil.,M.Tech Prepared by: A.Saleem Raja.,-Asst.Prof MCA pg. 1 UNIT III JAVA FUNDAMENTALS Java

More information

Programming in the Small II: Control

Programming in the Small II: Control Programming in the Small II: Control 188230 Advanced Computer Programming Asst. Prof. Dr. Kanda Runapongsa Saikaew (krunapon@kku.ac.th) Department of Computer Engineering Khon Kaen University Agenda Selection

More information

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017 Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor Sep 2017 Lecture 03: Control Flow Statements: Selection Instructor: AbuKhleif, Mohammad Noor Sep 2017 Instructor AbuKhleif, Mohammad Noor

More information

Practice with variables and types

Practice with variables and types Practice with variables and types 1. Types. For each literal or expression, state its type (String, int, double, or boolean). Expression Type Expression Type 387 "pancakes" true 45.0 "14" 87.98515 "false"

More information

Lecture 1 Java SE Programming

Lecture 1 Java SE Programming Lecture 1 Java SE Programming presentation Java Programming Software App Development Assoc. Prof. Cristian Toma Ph.D. D.I.C.E/D.E.I.C Department of Economic Informatics & Cybernetics www.dice.ase.ro cristian.toma@ie.ase.ro

More information

Programming Basics. Digital Urban Visualization. People as Flows. ia

Programming Basics.  Digital Urban Visualization. People as Flows. ia Programming Basics Digital Urban Visualization. People as Flows. 28.09.2015 ia zuend@arch.ethz.ch treyer@arch.ethz.ch Programming? Programming is the interaction between the programmer and the computer.

More information

Lecture 14 CSE11 Fall 2013 For loops, Do While, Break, Continue

Lecture 14 CSE11 Fall 2013 For loops, Do While, Break, Continue Lecture 14 CSE11 Fall 2013 For loops, Do While, Break, Continue General Loops in Java Look at other loop constructions Very common while loop: do a loop a fixed number of times (MAX in the example) int

More information

CSCI 136 Data Structures & Advanced Programming. Lecture 3 Fall 2018 Instructors: Bill & Bill

CSCI 136 Data Structures & Advanced Programming. Lecture 3 Fall 2018 Instructors: Bill & Bill CSCI 136 Data Structures & Advanced Programming Lecture 3 Fall 2018 Instructors: Bill & Bill Administrative Details Lab today in TCL 217a (and 216) Lab is due by 11pm Sunday Lab 1 design doc is due at

More information

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp DM550 / DM857 Introduction to Programming Peter Schneider-Kamp petersk@imada.sdu.dk http://imada.sdu.dk/~petersk/dm550/ http://imada.sdu.dk/~petersk/dm857/ CALLING & DEFINING FUNCTIONS 2 Functions and

More information

204111: Computer and Programming

204111: Computer and Programming 204111: Computer and Programming Week 4: Control Structures t Monchai Sopitkamon, Ph.D. Overview Types of control structures Using selection structure Using repetition structure Types of control ol structures

More information

Java Simple Data Types

Java Simple Data Types Intro to Java Unit 1 Multiple Choice Test Key Java Simple Data Types This Test Is a KEY DO NOT WRITE ON THIS TEST This test includes program segments, which are not complete programs. Answer such questions

More information

Java Loop Control. Programming languages provide various control structures that allow for more complicated execution paths.

Java Loop Control. Programming languages provide various control structures that allow for more complicated execution paths. Loop Control There may be a situation when you need to execute a block of code several number of times. In general, statements are executed sequentially: The first statement in a function is executed first,

More information

COSC 123 Computer Creativity. Java Decisions and Loops. Dr. Ramon Lawrence University of British Columbia Okanagan

COSC 123 Computer Creativity. Java Decisions and Loops. Dr. Ramon Lawrence University of British Columbia Okanagan COSC 123 Computer Creativity Java Decisions and Loops Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Key Points 1) A decision is made by evaluating a condition in an if/else

More information

Expressions & Flow Control

Expressions & Flow Control Objectives Distinguish between instance and local variables 4 Expressions & Flow Control Describe how instance variables are initialized Identify and correct a Possible reference before assignment compiler

More information

Learn more about our research, discover data science, and find other great resources at:

Learn more about our research, discover data science, and find other great resources at: Learn more about our research, discover data science, and find other great resources at: http://www.dataminingapps.com Chapter 5 Controlling the Flow of Your Program Overview Comparisons using Operators

More information

Iteration statements - Loops

Iteration statements - Loops Iteration statements - Loops : ) הוראות חזרה / לולאות ( statements Java has three kinds of iteration WHILE FOR DO... WHILE loop loop loop Iteration (repetition) statements causes Java to execute one or

More information

Java Control Statements

Java Control Statements Java Control Statements An introduction to the Java Programming Language Produced by: Eamonn de Leastar (edeleastar@wit.ie) Dr. Siobhan Drohan (sdrohan@wit.ie) Department of Computing and Mathematics http://www.wit.ie/

More information

University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ Test 2. Question Max Mark Internal External

University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ Test 2. Question Max Mark Internal External Name: Please fill in your Student Number and Name. Student Number : Student Number: University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ 2009 Test 2 Question Max Mark Internal

More information

Topic 5: Enumerated Types and Switch Statements

Topic 5: Enumerated Types and Switch Statements Topic 5: Enumerated Types and Switch Statements Reading: JBD Sections 6.1, 6.2, 3.9 1 What's wrong with this code? if (pressure > 85.0) excesspressure = pressure - 85.0; else safetymargin = 85.0 - pressure;!

More information

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line A SIMPLE JAVA PROGRAM Class Declaration The Main Line INDEX The Line Contains Three Keywords The Output Line COMMENTS Single Line Comment Multiline Comment Documentation Comment TYPE CASTING Implicit Type

More information

CSC Java Programming, Fall Java Data Types and Control Constructs

CSC Java Programming, Fall Java Data Types and Control Constructs CSC 243 - Java Programming, Fall 2016 Java Data Types and Control Constructs Java Types In general, a type is collection of possible values Main categories of Java types: Primitive/built-in Object/Reference

More information

Please answer the following questions. Do not re-code the enclosed codes if you have already completed them.

Please answer the following questions. Do not re-code the enclosed codes if you have already completed them. Dec. 9 Loops Please answer the following questions. Do not re-code the enclosed codes if you have already completed them. What is a loop? What are the three loops in Java? What do control structures do?

More information

Java Methods. Lecture 8 COP 3252 Summer May 23, 2017

Java Methods. Lecture 8 COP 3252 Summer May 23, 2017 Java Methods Lecture 8 COP 3252 Summer 2017 May 23, 2017 Java Methods In Java, the word method refers to the same kind of thing that the word function is used for in other languages. Specifically, a method

More information

data_type variable_name = value; Here value is optional because in java, you can declare the variable first and then later assign the value to it.

data_type variable_name = value; Here value is optional because in java, you can declare the variable first and then later assign the value to it. Introduction to JAVA JAVA is a programming language which is used in Android App Development. It is class based and object oriented programming whose syntax is influenced by C++. The primary goals of JAVA

More information

Building Java Programs. Introduction to Programming and Simple Java Programs

Building Java Programs. Introduction to Programming and Simple Java Programs Building Java Programs Introduction to Programming and Simple Java Programs 1 A simple Java program public class Hello { public static void main(string[] args) { System.out.println("Hello, world!"); code

More information

Object-Oriented Programming

Object-Oriented Programming Object-Oriented Programming Java Syntax Program Structure Variables and basic data types. Industry standard naming conventions. Java syntax and coding conventions If Then Else Case statements Looping (for,

More information

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science Department Lecture 3: C# language basics Lecture Contents 2 C# basics Conditions Loops Methods Arrays Dr. Amal Khalifa, Spr 2015 3 Conditions and

More information

RtUv)an sresrkñúgbribt HTML b:uenþminducca HTML page FmµtaenaHeTPHP script minrtuv)anbba Ún etaegay

RtUv)an sresrkñúgbribt HTML b:uenþminducca HTML page FmµtaenaHeTPHP script minrtuv)anbba Ún etaegay ច ច នទ យ ១ Introduction PHP History PHP RtUv)anpþl;eQµaHCapøÚvkar HyperText Preprocessor vacapasaedltmenirkarenaeli ServerEdlCa TUeTA RtUv)an sresrkñúgbribt HTML b:uenþminducca HTML page FmµtaenaHeTPHP

More information

Accelerating Information Technology Innovation

Accelerating Information Technology Innovation Accelerating Information Technology Innovation http://aiti.mit.edu Cali, Colombia Summer 2012 Lección 03 Control Structures Agenda 1. Block Statements 2. Decision Statements 3. Loops 2 What are Control

More information

COMP-202: Foundations of Programming. Lecture 8: for Loops, Nested Loops and Arrays Jackie Cheung, Winter 2016

COMP-202: Foundations of Programming. Lecture 8: for Loops, Nested Loops and Arrays Jackie Cheung, Winter 2016 COMP-202: Foundations of Programming Lecture 8: for Loops, Nested Loops and Arrays Jackie Cheung, Winter 2016 Review What is the difference between a while loop and an if statement? What is an off-by-one

More information

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Basic Operators Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

The Java language has a wide variety of modifiers, including the following:

The Java language has a wide variety of modifiers, including the following: PART 5 5. Modifier Types The Java language has a wide variety of modifiers, including the following: Java Access Modifiers Non Access Modifiers 5.1 Access Control Modifiers Java provides a number of access

More information

Module Contact: Dr Gavin Cawley, CMP Copyright of the University of East Anglia Version 1

Module Contact: Dr Gavin Cawley, CMP Copyright of the University of East Anglia Version 1 UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series UG Examination 2017-18 PROGRAMMING 1 CMP-4008Y Time allowed: 2 hours Answer FOUR questions. All questions carry equal weight. Notes are

More information

Selenium Class 9 - Java Operators

Selenium Class 9 - Java Operators Selenium Class 9 - Java Operators Operators are used to perform Arithmetic, Comparison, and Logical Operations, Operators are used to perform operations on variables and values. public class JavaOperators

More information

3chapter C ONTROL S TATEMENTS. Objectives

3chapter C ONTROL S TATEMENTS. Objectives 3chapter C ONTROL S TATEMENTS Objectives To understand the flow of control in selection and loop statements ( 3.2 3.7). To use Boolean expressions to control selection statements and loop statements (

More information

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018 Object-oriented programming 1 and data-structures CS/ENGRD 2110 SUMMER 2018 Lecture 1: Types and Control Flow http://courses.cs.cornell.edu/cs2110/2018su Lecture 1 Outline 2 Languages Overview Imperative

More information

Operators Questions

Operators Questions Operators Questions https://www.geeksforgeeks.org/java-operators-question-1/ https://www.indiabix.com/java-programming/operators-andassignments/ http://www.instanceofjava.com/2015/07/increment-decrementoperators-interview.html

More information

SOFTWARE DEVELOPMENT 1. Control Structures 2018W A. Ferscha (Institute of Pervasive Computing, JKU Linz)

SOFTWARE DEVELOPMENT 1. Control Structures 2018W A. Ferscha (Institute of Pervasive Computing, JKU Linz) SOFTWARE DEVELOPMENT 1 Control Structures 2018W (Institute of Pervasive Computing, JKU Linz) WHAT IS CONTROL FLOW? The control flow determines the order in which instructions are executed. Default: from

More information

Key Points. COSC 123 Computer Creativity. Java Decisions and Loops. Making Decisions Performing Comparisons. Making Decisions

Key Points. COSC 123 Computer Creativity. Java Decisions and Loops. Making Decisions Performing Comparisons. Making Decisions COSC 123 Computer Creativity Java Decisions and Loops Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Key Points 1) A decision is made by evaluating a condition in an if/

More information

Repe$$on CSC 121 Spring 2017 Howard Rosenthal

Repe$$on CSC 121 Spring 2017 Howard Rosenthal Repe$$on CSC 121 Spring 2017 Howard Rosenthal Lesson Goals Learn the following three repetition structures in Java, their syntax, their similarities and differences, and how to avoid common errors when

More information

Discover how to get up and running with the Java Development Environment and with the Eclipse IDE to create Java programs.

Discover how to get up and running with the Java Development Environment and with the Eclipse IDE to create Java programs. Java SE11 Development Java is the most widely-used development language in the world today. It allows programmers to create objects that can interact with other objects to solve a problem. Explore Java

More information

Review. Primitive Data Types & Variables. String Mathematical operators: + - * / % Comparison: < > <= >= == int, long float, double boolean char

Review. Primitive Data Types & Variables. String Mathematical operators: + - * / % Comparison: < > <= >= == int, long float, double boolean char Review Primitive Data Types & Variables int, long float, double boolean char String Mathematical operators: + - * / % Comparison: < > = == 1 1.3 Conditionals and Loops Introduction to Programming in

More information

Loops! Loops! Loops! Lecture 5 COP 3014 Fall September 25, 2017

Loops! Loops! Loops! Lecture 5 COP 3014 Fall September 25, 2017 Loops! Loops! Loops! Lecture 5 COP 3014 Fall 2017 September 25, 2017 Repetition Statements Repetition statements are called loops, and are used to repeat the same code mulitple times in succession. The

More information

Control Structures in Java if-else and switch

Control Structures in Java if-else and switch Control Structures in Java if-else and switch Lecture 4 CGS 3416 Spring 2017 January 23, 2017 Lecture 4CGS 3416 Spring 2017 Selection January 23, 2017 1 / 26 Control Flow Control flow refers to the specification

More information

Java Application Development

Java Application Development In order to learn which questions have been answered correctly: 1. Print these pages. 2. Answer the questions. 3. Send this assessment with the answers via: a. FAX to (212) 967-3498. Or b. Mail the answers

More information

CSE 201 JAVA PROGRAMMING I. Copyright 2016 by Smart Coding School

CSE 201 JAVA PROGRAMMING I. Copyright 2016 by Smart Coding School CSE 201 JAVA PROGRAMMING I Primitive Data Type Primitive Data Type 8-bit signed Two s complement Integer -128 ~ 127 Primitive Data Type 16-bit signed Two s complement Integer -32768 ~ 32767 Primitive Data

More information

DM503 Programming B. Peter Schneider-Kamp.

DM503 Programming B. Peter Schneider-Kamp. DM503 Programming B Peter Schneider-Kamp petersk@imada.sdu.dk! http://imada.sdu.dk/~petersk/dm503/! VARIABLES, EXPRESSIONS & STATEMENTS 2 Values and Types Values = basic data objects 42 23.0 "Hello!" Types

More information

COMP-202 Unit 4: Programming With Iterations. CONTENTS: The while and for statements

COMP-202 Unit 4: Programming With Iterations. CONTENTS: The while and for statements COMP-202 Unit 4: Programming With Iterations CONTENTS: The while and for statements Introduction (1) Suppose we want to write a program to be used in cash registers in stores to compute the amount of money

More information

Chapter 3 Selections. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved.

Chapter 3 Selections. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved. Chapter 3 Selections Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved. 0132130807 1 Motivations If you assigned a negative value for radius

More information

6 COMPUTER PROGRAMMING

6 COMPUTER PROGRAMMING 6 COMPUTER PROGRAMMING ITERATION STATEMENT CONTENTS WHILE DO~WHILE FOR statement 2 Iteration Statement provides While / do-while / For statements for supporting an iteration logic function that the logic

More information

Write a program which converts all lowercase letter in a sentence to uppercase.

Write a program which converts all lowercase letter in a sentence to uppercase. Write a program which converts all lowercase letter in a sentence to uppercase. For Example: 1) Consider a sentence "welcome to Java Programming!" its uppercase conversion is " WELCOME TO JAVA PROGRAMMING!"

More information

n Group of statements that are executed repeatedly while some condition remains true

n Group of statements that are executed repeatedly while some condition remains true Looping 1 Loops n Group of statements that are executed repeatedly while some condition remains true n Each execution of the group of statements is called an iteration of the loop 2 Example counter 1,

More information

Admin. CS 112 Introduction to Programming. Recap: Exceptions. Summary: for loop. Recap: CaesarFile using Loop. Summary: Flow Control Statements

Admin. CS 112 Introduction to Programming. Recap: Exceptions. Summary: for loop. Recap: CaesarFile using Loop. Summary: Flow Control Statements Admin. CS 112 Introduction to Programming q Puzzle Day from Friday to Monday Arrays; Loop Patterns (break) Yang (Richard) Yang Computer Science Department Yale University 308A Watson, Phone: 432-6400 Email:

More information

Glossary. (Very) Simple Java Reference (draft, v0.2)

Glossary. (Very) Simple Java Reference (draft, v0.2) (Very) Simple Java Reference (draft, v0.2) (Very) Simple Java Reference (draft, v0.2) Explanations and examples for if and for (other things to-be-done). This is supposed to be a reference manual, so we

More information

Key Java Simple Data Types

Key Java Simple Data Types AP CS P w Java Unit 1 Multiple Choice Practice Key Java Simple Data Types This test includes program segments, which are not complete programs. Answer such questions with the assumption that the program

More information

CS 112 Introduction to Programming

CS 112 Introduction to Programming CS 112 Introduction to Programming Arrays; Loop Patterns (break) Yang (Richard) Yang Computer Science Department Yale University 308A Watson, Phone: 432-6400 Email: yry@cs.yale.edu Admin. q Puzzle Day

More information