Lecture Java methods: Object-oriented programming and data structures (2nd AP edition): Chapter 12 - Maria Litvin, Gary Litvin

Chapter 12 - Arrays. This chapter’s objectives are to: Learn about arrays and when to use them, learn the syntax for declaring and initializing arrays and how to access array’s size and elements, learn about the class, discuss “for each” loops, learn simple array algorithms, understand two-dimensional arrays. | Arrays Section[] chapter12 = new Section[8] Copyright © 2011 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. Java Methods Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin 2nd AP edition with GridWorld 12- 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 simple array algorithms 12- 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 12- There is indeed some confusion in the usage of “element.” In some situations, | Arrays Section[] chapter12 = new Section[8] Copyright © 2011 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. Java Methods Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin 2nd AP edition with GridWorld 12- 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 simple array algorithms 12- 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 12- 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 12- 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

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
200    14    2    16-06-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.