复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 5 Arrays

Chapter 5 Arrays Prerequisites for Part I Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word hapter I Introduction to Computers, Programs, and java Chapter 2 Primitive Data Types and operations Chapter 3 Control Statements Chapter 4 Methods hapter 5 Arrays 最终也要试一试,千万别站在那里犹豫 Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 1 Chapter 5 Arrays Chapter 1 Introduction to Computers, Programs, and Java Chapter 2 Primitive Data Types and Operations Chapter 3 Control Statements Chapter 5 Arrays Chapter 4 Methods Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word Prerequisites for Part I 最终也要试一试,千万别站在那里犹豫

Objectives o To describe why an array is necessary in programming($ 5.1) o To learn the steps involved in using arrays: declaring array reference variables and creating arrays( s 5.2) ● To initialize the values in an array(§52) o To simplify programming using JDK 1.5 enhanced for loop(s 5.2) ● To copy contents from one array to another(§53 To develop and invoke methods with array arguments and ruturn type(§5455) o To sort an array using the selection sort algorithm($ 5.6) To search elements using the linear or binary search algorithm o To declare and create multidimensional arrays($ 5.8) o To declare and create multidimensional arrays($5.9 Optional) Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 2 Objectives ⚫ To describe why an array is necessary in programming (§5.1). ⚫ To learn the steps involved in using arrays: declaring array reference variables and creating arrays (§5.2). ⚫ To initialize the values in an array (§5.2). ⚫ To simplify programming using JDK 1.5 enhanced for loop (§5.2). ⚫ To copy contents from one array to another (§5.3). ⚫ To develop and invoke methods with array arguments and ruturn type (§5.4-5.5). ⚫ To sort an array using the selection sort algorithm (§5.6). ⚫ To search elements using the linear or binary search algorithm (§5.7). ⚫ To declare and create multidimensional arrays (§5.8). ⚫ To declare and create multidimensional arrays (§5.9 Optional)

Introducing arrays ● Array in logical O Data structures o Related data items of same type O Remain same size once created ● array in physical O Group of contiguous memory locations o Each memory location has same name o Each memory location has same type Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 3 Introducing Arrays ⚫ Array in logical Data structures Related data items of same type Remain same size once created ⚫ Array in physical Group of contiguous memory locations ⚫Each memory location has same name ⚫Each memory location has same type

Name of array(note c[0 45 that all elements of c this array have the 6 same name c) c[2 0 c[3 72 1543 c 89 c[6 0 c[7 62 3 Position number(index c[9 1 of subscript)of the 6453 element within array c c[10] [11] 78 Fig. 7.1 A 12-element array Liang, Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 4 Fig. 7.1 A 12-element array. -45 6 0 72 1543 -89 0 62 -3 1 6453 78 c[ 1 ] c[ 2 ] c[ 4 ] c[ 3 ] c[ 5 ] c[ 6 ] c[ 7 ] c[ 8 ] c[ 9 ] c[ 10 ] c[ 11 ] c[ 0 ] Name of array (Note that all elements of this array have the same name, c) Position number (index of subscript) of the element within array c

Introducing arrays array is a data structure that represents a collection of the same types of data doublel] myList=new double[1 myList reference L 5.6 my List[1] 4.5 Array reference my List[2] 3.3 variable myList3] 13.2 4 Array element at index 5 e myList[5] 34.33 Element value my List 6 34 myList[7] 45.45 myList[ 8] 99993 my List 11123 Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 5 Introducing Arrays Array is a data structure that represents a collection of the same types of data. 5.6 4.5 3.3 13.2 4 34.33 34 45.45 99.993 11123 double[] myList = new double[10]; myList reference myList[0] myList[1] myList[2] myList[3] myList[4] myList[5] myList[6] myList[7] myList[8] myList[9] Element value Array reference variable Array element at index 5

Declaring A rray variables datatype[ array Refvar Example Declaring dosent allocate memory for array but for doublel mylist the reference o datatype array RefVar[; //This style is correct, but not referred Example double my list[ when declaring, we cant give the number of the element int c [23] is wrong; Liang, Introduction to Java Programming, reused by Dal-Kalyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 6 Declaring Array Variables ⚫ datatype[] arrayRefVar; Example: double[] myList; ⚫ datatype arrayRefVar[]; // This style is correct, but not preferred Example: double myList[]; Declaring dosen’t allocate memory for array, but for the reference When declaring , we can’t give the number of the element int c [23] is wrong;

Creating arrays arrayRef Var = new datatypelarraySize] Example mylist =new double[10] ● Subscript O Also called an index O Position number in square brackets O Must be integer or integer expression my List[O] references the first element in the array myList[9] references the last element in the array Liang, Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 7 Creating Arrays arrayRefVar = new datatype[arraySize]; Example: myList = new double[10]; ⚫ Subscript Also called an index Position number in square brackets Must be integer or integer expression myList[0] references the first element in the array. myList[9] references the last element in the array

Declaring and Creating in One step o datatype arrayRefvar=new datatype[array Size doublel mylist=new double[10 o datatype array Ref var=new datatype array Size double my list[=new double[10] Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 8 Declaring and Creating in One Step ⚫ datatype[] arrayRefVar = new datatype[arraySize]; double[] myList = new double[10]; ⚫ datatype arrayRefVar[] = new datatype[arraySize]; double myList[] = new double[10];

The Length of an Array Once an array is created, its size is fixed. It cannot be changed. You can find its size using arrayRefVar length Compare with String For example, my List length returns 10 Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 9 The Length of an Array Once an array is created, its size is fixed. It cannot be changed. You can find its size using arrayRefVar.length For example, myList.length returns 10 Compare with String

Default values When an array is created, its elements are assigned the default value of 0 for the numeric primitive data types, 1uo0oo' for char types, and false for boolean types Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 10 Default Values When an array is created, its elements are assigned the default value of 0 for the numeric primitive data types, '\u0000'for char types, and false for boolean types
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 4 Methods.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 3 Control Statements.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 2 Primitive Data Types and Operations.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 1 Introduction to Computers, Programs, and Java.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 0 course intro Programming Language(Using Java).ppt
- 复旦大学:《程序设计》课程教学资源(Java Lab)Game of Life_题目要求.pdf
- 复旦大学:《程序设计》课程教学资源(Java Lab)Game of Life.ppt
- 复旦大学:《程序设计》课程教学资源(Java Lab)验证哥德巴赫猜想.ppt
- 复旦大学:《程序设计》课程教学资源(Java Lab)Ansi Temple.ppt
- 复旦大学:《程序设计》课程教学资源(Java Lab)富人Smith的生日 If else Switch.ppt
- 复旦大学:《程序设计》课程教学资源(Java Lab)3.ppt
- 复旦大学:《程序设计》课程教学资源(Java Lab)环境配置与第一个程序的运行.ppt
- 复旦大学:《程序设计》课程教学资源(Java Lab)第一个java程序.ppt
- 《高级Web技术》参考资料:语义Web课件 A Semantic Web Primer_Chapter8 Conclusion and Outlook.ppt
- 《高级Web技术》参考资料:语义Web课件 A Semantic Web Primer_Chapter7 Ontology Engineering.ppt
- 《高级Web技术》参考资料:语义Web课件 A Semantic Web Primer_Chapter6 Applications.ppt
- 《高级Web技术》参考资料:语义Web课件 A Semantic Web Primer_Chapter5 Logic and Inference:Rules.ppt
- 《高级Web技术》参考资料:语义Web课件 A Semantic Web Primer_Chapter4 Web Ontology Language:OWL.ppt
- 《高级Web技术》参考资料:语义Web课件 A Semantic Web Primer_Chapter3 Describing Web Resources in RDF.ppt
- 《高级Web技术》参考资料:语义Web课件 A Semantic Web Primer_Chapter2 Structured Web Documents in XML.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 6 Objects and Classes.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 7 String.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 8 Inheritance and Polymorphism.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 9 Abstract Classes and Interfaces.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 10 Object-Oriented Modeling(oom).ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 11 Getting Started with GUI Programming.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 12 Event-Driven Programming.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 13 Creating User Interfaces.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 14 Applets, Images, and Audio.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 15 Exceptions and Assertions.ppt
- 复旦大学:《程序设计》课程教学资源(PPT课件)Chapter 16 Simple Input and Output.ppt
- 复旦大学:《信息安全》教学课件_01 Classical Encryption Techniques.pdf
- 复旦大学:《信息安全》教学课件_02 Classical Encryption Techniques(cont.).pdf
- 复旦大学:《信息安全》教学课件_03 Modern Block Ciphers.pdf
- 复旦大学:《信息安全》教学课件_04 Public Key Cryptography, RSA.pdf
- 复旦大学:《信息安全》教学课件_05 Message authentication and Hash function.pdf
- 复旦大学:《信息安全》教学课件_06 The Intro to Information Security.pdf
- 复旦大学:《信息安全》教学课件_07-08 Public Key Infrastructure(PKI)公钥基础设施——公钥技术的应用.pdf
- 复旦大学:《信息安全》教学课件_09 Authentication and supplements.pdf
- 复旦大学:《信息安全》教学课件_10 Authentication Kerberos.pdf