Difference between revisions of "Arrays"

From CompSciWiki
Jump to: navigation, search
m ("students" to "student's" for possessive + other minor fixes)
 
(17 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{1010Chapter|Introduction=(Graham)
+
{{1010Chapter|ChapterNum=7
 +
|Picture=Wiki_array01.jpg
 +
|Introduction=Imagine that you are writing a program that will calculate the average mark of all students in a class.  You know from experience that ''variables'' are used to hold data (like a particular student's mark).  However, you realize that the class has more than 50 students and so you decide not to use a variable for each individual student.  You know that using a variable for each student is overkill.  Arrays are incredibly useful in this situation.  A variable is a piece of data, whereas an array is a list of data.
  
This section will discuss how to create arrays, use elements in arrays, as well as other various topics listed in the index.
+
With an array you can use a single variable ''student_marks'' to hold '''all''' the marks for each student in the class.  This chapter will cover how to create an array, how to manage data in an array, common errors when using arrays, and processing arrays with for loops.
  
Arrays are important in Java, since they can be used to store multiple pieces of data. You can at any time add, edit, or modify the elements within an array. In addition, you can at any time remove the elements from the array.
 
  
You can think of an array as a table of contents for a book. The array contains the exact location of the data you "insert" into it, so you can access it at any time. You can also modify elements contained in an array outside of the array, and both copies will be simultaneously changed.
+
|Body=
 +
==[[Creating Arrays]]==
 +
==[[Entering and Using Array Elements]]==
 +
==[[Out of Bounds and One off Errors]]==
 +
==[[Processing Arrays (using for loops)]]==
 +
==[[Arrays Review Questions and Exercises|Review Questions and Exercises]]==
  
Arrays have many things you need to consider when using, such as that you can never change the length of an array without losing the elements inside of an array. In addition, you may not ask for elements past the end of an array. We will discuss these and more in further detail later in the chapter.
+
 
 +
|PChapterNum=6
 +
|PChapterLink=[[User Defined Methods]]
 +
|NChapterNum=8
 +
|NChapterLink=[[More With Arrays]]
 
}}
 
}}
  
  
=[[Creating Arrays]]=
+
{{Category:COMP 1010}}
=[[Entering and Using Array Elements]]=
+
=[[Out of Bounds and One off Errors]]=
+
=[[Processing Arrays (using for loops)]]=
+
*length attribute
+
**print content of array
+
**copying arrays
+
**comparing arrays
+
**summing values
+
**finding average of values
+
**find highest and lowest values
+
=[[Chapter 8 Review Questions and Exercises|Review Questions and Exercises]]=
+

Latest revision as of 02:00, 8 December 2011


Wiki 1010 Table of Contents

Wiki array01.jpg

Chapter 7

Imagine that you are writing a program that will calculate the average mark of all students in a class. You know from experience that variables are used to hold data (like a particular student's mark). However, you realize that the class has more than 50 students and so you decide not to use a variable for each individual student. You know that using a variable for each student is overkill. Arrays are incredibly useful in this situation. A variable is a piece of data, whereas an array is a list of data.

With an array you can use a single variable student_marks to hold all the marks for each student in the class. This chapter will cover how to create an array, how to manage data in an array, common errors when using arrays, and processing arrays with for loops.

  Write a Program a Day Case Studies

Creating Arrays

Entering and Using Array Elements

Out of Bounds and One off Errors

Processing Arrays (using for loops)

Review Questions and Exercises




Chapter 6: User Defined Methods Table of Contents Chapter 8: More With Arrays



Template loop detected: