tailieunhanh - Lecture Java methods: Object-oriented programming and data structures (3rd AP edition): Chapter 9 - Maria Litvin, Gary Litvin
Chapter 9 - Implementing classes and using objects. This is a long and technical chapter: it deals with several important Java concepts and syntax details. These objectives are within the AP Java Subset for the A-level exam. Some of the details related to classes and methods are left out. Java is a big language. | Arrays Section[] chapter9 = new Section[9] Copyright © 2015 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. Java Methods Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin 3rd AP edition 9- This chapter also introduces the “for each” loop and reviews nested loops. Objectives: Learn about one- and two-dimensional arrays and when to use them Learn the syntax for declaring and initializing arrays and how to access array’s size and elements Discuss “for each” loops Learn several array algorithms 9- This material, including 2-D arrays, is in the A-level AP subset. What is an Array An array is a block of consecutive memory locations that hold values of the same data type. Individual locations are called array’s elements. When we say “element” we often mean the value stored in that element. An array of doubles 9- There is indeed some confusion in the usage of “element.” In some situations, the word refers to . | Arrays Section[] chapter9 = new Section[9] Copyright © 2015 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. Java Methods Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin 3rd AP edition 9- This chapter also introduces the “for each” loop and reviews nested loops. Objectives: Learn about one- and two-dimensional arrays and when to use them Learn the syntax for declaring and initializing arrays and how to access array’s size and elements Discuss “for each” loops Learn several array algorithms 9- This material, including 2-D arrays, is in the A-level AP subset. What is an Array An array is a block of consecutive memory locations that hold values of the same data type. Individual locations are called array’s elements. When we say “element” we often mean the value stored in that element. An array of doubles 9- There is indeed some confusion in the usage of “element.” In some situations, the word refers to the location in an array, as in “set the value of the k-th element.” In other situations it refers to a value stored in the array, as in “find the smallest element.” This dual usage is somewhat similar to the situation with the term “variable.” This is no big deal, as long as everyone understands the difference between a location and a value stored in it. What is an Array (cont’d) Rather than treating each element as a separate named variable, the whole array gets one name. Specific array elements are referred to by using array’s name and the element’s number, called index or subscript. c[0] c[1] c[2] c[3] c is array’s name 9- The idea is not to save names, of course, but to be able to handle an array’s elements uniformly, using algorithms. Indices (Subscripts) In Java, an index is written within square brackets following array’s name (for example, a[k]). Indices start from 0; the first element of an array a is referred to as a[0] and the n-th element as a[n-1]. .
đang nạp các trang xem trước