欢迎来到天天文库
浏览记录
ID:51963930
大小:2.34 MB
页数:111页
时间:2020-03-26
《Java语言程序设计10E LiangPPT习题案例07slide.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、1Chapter7Single-DimensionalArrays2OpeningProblemReadonehundrednumbers,computetheiraverage,andfindouthowmanynumbersareabovetheaverage.3ObjectivesTodescribewhyarraysarenecessaryinprogramming(§7.1).Todeclarearrayreferencevariablesandcreatearrays(§§7.2.1–7.2.2).Toobtainarraysizeusingar
2、rayRefVar.lengthandknowdefaultvaluesinanarray(§7.2.3).Toaccessarrayelementsusingindexes(§7.2.4).Todeclare,create,andinitializeanarrayusinganarrayinitializer(§7.2.5).Toprogramcommonarrayoperations(displayingarrays,summingallelements,findingtheminimumandmaximumelements,randomshufflin
3、g,andshiftingelements)(§7.2.6).Tosimplifyprogrammingusingtheforeachloops(§7.2.7).Toapplyarraysinapplicationdevelopment(AnalyzeNumbers,DeckOfCards)(§§7.3–7.4).Tocopycontentsfromonearraytoanother(§7.5).Todevelopandinvokemethodswitharrayargumentsandreturnvalues(§§7.6–7.8).Todefineamet
4、hodwithavariable-lengthargumentlist(§7.9).Tosearchelementsusingthelinear(§7.10.1)orbinary(§7.10.2)searchalgorithm.Tosortanarrayusingtheselectionsortapproach(§7.11).Tousethemethodsinthejava.util.Arraysclass(§7.12).Topassargumentstothemainmethodfromthecommandline(§7.13).4IntroducingA
5、rraysArrayisadatastructurethatrepresentsacollectionofthesametypesofdata.5DeclaringArrayVariablesdatatype[]arrayRefVar;Example:double[]myList;datatypearrayRefVar[];//Thisstyleisallowed,butnotpreferredExample:doublemyList[];6CreatingArraysarrayRefVar=newdatatype[arraySize];Example:my
6、List=newdouble[10];myList[0]referencesthefirstelementinthearray.myList[9]referencesthelastelementinthearray.7DeclaringandCreatinginOneStepdatatype[]arrayRefVar=newdatatype[arraySize];double[]myList=newdouble[10];datatypearrayRefVar[]=newdatatype[arraySize];doublemyList[]=newdoubl
7、e[10];8TheLengthofanArrayOnceanarrayiscreated,itssizeisfixed.Itcannotbechanged.YoucanfinditssizeusingarrayRefVar.lengthForexample,myList.lengthreturns109DefaultValuesWhenanarrayiscreated,itselementsareassignedthedefaultvalueof0forthenumericprimitivedatatypes,'u0000'forchartypes,an
8、dfalseforbooleantypes.10In
此文档下载收益归作者所有