Array Flashcards

1
Q

It stores a fixed-size sequential collection of elements of the same type.

A

Array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element.

A

Array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Syntax for declaring an array variable

A

datatype[] arrayName;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Syntax for creating an array

A

arrayName= new datatype[arraySize];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the two things that the following statement does?
arrayName= new datatype[arraySize]

A
  • It creates an array using new dataType[arraySize].
  • It assigns the reference of the newly created array to the variable arrayName.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Syntax for declaring array variable, creating an array, and assigning the reference of the array to the variable in one line

A

datatype[] arrayName = new datatype[arraySize];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Identify the parts of the following.
char[] letters = new char[41];

A

char - data type
letters - array name
[41] - array size

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the highest index of array?

A

The highest index of array is the array size - 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What number does the array in Java always start in?

A

The array in Java always start in zero

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the value of the array if not initialized?

A

The array value if not initialized is zero for number/null for the object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

The number that is assigned to each element in an array

A

Subscript

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

used as an index to pinpoint a specific element within an array

A

Subscript

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Identify the values of the elements.
int[] num = new int[6];
num[1]= 20;
num[4]= 15;
num[3]= num[1] + num[4];
int x= 2;
num[x] = 5;
int y=1;
num[y-1] = 40;
num[4++]=18;

A

num[1] - 20
num[2] - 5
num[3] - 35
num[4] - 15
num[5] - 18

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What would happen?
int[] num = new int[6];

A

Array IndexOutofBound Error since the highest index of array subscript is 5 only

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Can you can read values from the keyboard and store them in an array element?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

This public field contains the number of elements in the array.

A

length

17
Q

can be used in looping instead of the actual size of the array

A

length

18
Q

Syntax for array initialization

A

datatype [] arrayName = {v1, v2, v3…..vn}

19
Q

Java provides a specialized version of the for loop that, in many circumstances, simplifies array processing.

A

Enhanced for loop

20
Q

designed to iterate once for every element in an array.

A

Enhanced for loop

21
Q

What is the general format of the enhanced for loop?

A

for (datatype variable: array) {

}

22
Q

Identify the parts of the enhanced for loop
for (datatype variable: array) {

}

A

datatype variable - It is a variable declaration. This variable will receive the value of a different array element during each loop iteration. During the first loop iteration, it receives the value of the first element; during the second iteration, it receives the value of the second element, and so on.
array - It is the name of an array on which you wish the loop to operate. The loop will iterate once for every element in the array.

23
Q

What would the output be?
int[] num = { 12, 56, 78, 90, 92 };
System.out.println(“Enhance For Loop”);
for(int number : num){
System.out.print(number + “ “);
}

A

Enhance For Loop
12 56 78 90 92