欢迎来到天天文库
浏览记录
ID:51963934
大小:895.50 KB
页数:42页
时间:2020-03-26
《Java语言程序设计10E LiangPPT习题案例04slide.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、1Chapter4MathematicalFunctions,Characters,andStrings2MotivationsSupposeyouneedtoestimatetheareaenclosedbyfourcities,giventheGPSlocations(latitudeandlongitude)ofthesecities,asshowninthefollowingdiagram.Howwouldyouwriteaprogramtosolvethisproblem?Youwillbeabletowritesuchaprogramafterc
2、ompletingthischapter.3ObjectivesTosolvemathematicsproblemsbyusingthemethodsintheMathclass(§4.2).Torepresentcharactersusingthechartype(§4.3).ToencodecharactersusingASCIIandUnicode(§4.3.1).Torepresentspecialcharactersusingtheescapesequences(§4.4.2).Tocastanumericvaluetoacharacterandc
3、astacharactertoaninteger(§4.3.3).TocompareandtestcharactersusingthestaticmethodsintheCharacterclass(§4.3.4).Tointroduceobjectsandinstancemethods(§4.4).TorepresentstringsusingtheStringobjects(§4.4).Toreturnthestringlengthusingthelength()method(§4.4.1).Toreturnacharacterinthestringus
4、ingthecharAt(i)method(§4.4.2).Tousethe+operatortoconcatenatestrings(§4.4.3).Toreadstringsfromtheconsole(§4.4.4).Toreadacharacterfromtheconsole(§4.4.5).TocomparestringsusingtheequalsmethodandthecompareTomethods(§4.4.6).Toobtainsubstrings(§4.4.7).Tofindacharacterorasubstringinastring
5、usingtheindexOfmethod(§4.4.8).Toprogramusingcharactersandstrings(GuessBirthday)(§4.5.1).Toconvertahexadecimalcharactertoadecimalvalue(HexDigit2Dec)(§4.5.2).Torevisethelotteryprogramusingstrings(LotteryUsingStrings)(§4.5.3).ToformatoutputusingtheSystem.out.printfmethod(§4.6).4Mathem
6、aticalFunctionsJavaprovidesmanyusefulmethodsintheMathclassforperformingcommonmathematicalfunctions.5TheMathClassClassconstants:PIEClassmethods:TrigonometricMethodsExponentMethodsRoundingMethodsmin,max,abs,andrandomMethods6TrigonometricMethodssin(doublea)cos(doublea)tan(doublea)acos
7、(doublea)asin(doublea)atan(doublea)RadianstoRadians(90)Examples:Math.sin(0)returns0.0Math.sin(Math.PI/6)returns0.5Math.sin(Math.PI/2)returns1.0Math.cos(0)returns1.0Math.cos(Math.PI/6)returns0.866Math.cos(Math.PI/2)returns07ExponentMethodsexp(doublea)Returnseraisedtothepowerofa.log(
8、doublea)Returnsthenaturall
此文档下载收益归作者所有