Arrays- A data structure that makes it easier to handle similar types of data.
Arrays can store primitive or object data types.
Every separate piece of data is referred to as an element, and an index is used to identify the specific location of this element.
Arrays can be used to make the run-time of code a lot more efficient.
Primitives and Objects play a huge role in setting up an array. Use these steps to set up your array effectively.
The best way to teach this concept is by example, which is what we will walk through.
Decide on the types of data that will be stored in the array.
int [] <identifier> = new int [<array size>];
int [] <identifier> = {<data1>, <data2>, <datan>}
int[] testGrades = new int [5];
testGrades[0] = 95;
int [] testScores = {90, 80, 100, 85, 92};
testGrades[0] = 98;
for( int index = 0; index < testGrades.length ; index++)
testGrades[index]-=2;
int total = 0, len = testGrades.length;
double average;
for (int index = 0; index < len; index++)
total += testGrades[index];
average = (double) total/len;
int total = 0, len = testGrades.length;
double average;
for (int grade: testGrades)
total += grade;
average = (double) total/len;
\