资源描述:
《Java语言程序设计与数据结构 基础篇原书第11版PPT及其他教辅资源03slide.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Liang,IntroductiontoJavaProgramming,EleventhEdition,(c)2017PearsonEducation,Inc.Allrightsreserved.1Chapter3Selections2MotivationsIfyouassignedanegativevalueforradiusinListing2.2,ComputeAreaWithConsoleInput.java,theprogramwouldprintaninvalidresult.Iftheradiusisnegative,youdon'twanttheprog
2、ramtocomputethearea.Howcanyoudealwiththissituation?Liang,IntroductiontoJavaProgramming,EleventhEdition,(c)2017PearsonEducation,Inc.Allrightsreserved.3ObjectivesTodeclarebooleanvariablesandwriteBooleanexpressionsusingrelationaloperators(§3.2).Toimplementselectioncontrolusingone-wayifstate
3、ments(§3.3).Toimplementselectioncontrolusingtwo-wayif-elsestatements(§3.4).Toimplementselectioncontrolusingnestedifandmulti-wayifstatements(§3.5).Toavoidcommonerrorsandpitfallsinifstatements(§3.6).TogeneraterandomnumbersusingtheMath.random()method(§3.7).Toprogramusingselectionstatementsf
4、oravarietyofexamples(SubtractionQuiz,BMI,ComputeTax)(§§3.7–3.9).Tocombineconditionsusinglogicaloperators(&&,
5、
6、,and!)(§3.10).Toprogramusingselectionstatementswithcombinedconditions(LeapYear,Lottery)(§§3.11–3.12).Toimplementselectioncontrolusingswitchstatements(§3.13).Towriteexpressionsusi
7、ngtheconditionalexpression(§3.14).Toexaminetherulesgoverningoperatorprecedenceandassociativity(§3.15).Toapplycommontechniquestodebugerrors(§3.16).4ThebooleanTypeandOperatorsOfteninaprogramyouneedtocomparetwovalues,suchaswhetheriisgreaterthanj.Javaprovidessixcomparisonoperators(alsoknowna
8、srelationaloperators)thatcanbeusedtocomparetwovalues.TheresultofthecomparisonisaBooleanvalue:trueorfalse.booleanb=(1>2);5RelationalOperators6Problem:ASimpleMathLearningToolRunThisexamplecreatesaprogramtoletafirstgraderpracticeadditions.Theprogramrandomlygeneratestwosingle-digitintegersnu
9、mber1andnumber2anddisplaysaquestionsuchas“Whatis7+9?”tothestudent.Afterthestudenttypestheanswer,theprogramdisplaysamessagetoindicatewhethertheansweristrueorfalse.IMPORTANTNOTE:Ifyoucannotrunthebuttons,seeliveexample.pearsoncmg.com/slide/javaslidenote.doc.AdditionQuiz7One-