14. Arrays Flashcards

1
Q

Does an array object have a variable or a fixed size?

A

ss

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

Do we need to change the program source code in order to change the size of an array used by a program?

A

ss

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

Which of the following variable declarations are legal?

  1. int {} smallPrimes = {2, 3, 5, 7, 11, 13, 17, 19};
  2. int [] smallPrimes = [2, 3, 5, 7, 11, 13, 17, 19];
  3. int [] smallPrimes = {2, 3, 5, 7, 11, 13, 17, 19};
  4. int {} smallPrimes = [2, 3, 5, 7, 11, 13, 17, 19];
A

ss

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

How many in variables are created by the following code?

int[][] anArray = new int[4][];
for (int index = 0; index < anArray.length; index++)
anArray[index] = new int[index];

A

ss

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

How many references are involved in the following?

int[][] my2DArray = new int[5][4]

A

20

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

What set of indices does an array of ten elements have?

A

ss

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

Consider the following.
int[][] my2DArray = new int[5][4];

Which element is acces by my2DArray[4][1]?

  1. The first element in the last row.
  2. The second element in the last row.
  3. The first element in the penultimate row.
  4. The fourth element in the first row.
  5. The third element in the first row.
A

ss

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

How do we find the length of an array?

A

ss

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

What is the difference between and array variable containing null, and one containing a reference to an empty array?

A

ss

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

What does an ‘array of objects’ contain?

A

ss

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

What other variable do we need to support a partially filled array?

A

ss

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

What is the minimum size increase when extending an array? What is a good size increase?

A

ss

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

What is the difference between shallow and deep copies?

A

ss

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

How does linear search in a list work?

A

ss

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

Give three examples of a sort order on simple data, such as numbers or names.

A

ss

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

When using bubble sort for an array of length n, how many pair comparisons are needed worst case? (I.e. how many passes, and how many pairs on each pass?

A

ss

17
Q

What is the essential difference between double division by zero and that of integer division?

A

ss

18
Q

Which of the following expressions could produce an exception, where size and sum are int variables?

  1. size == 0 || sum / size >= 0
  2. sum / size < 10 && size != 0
A

ss

19
Q

What is the most obvious example of accepting parameters of an array type?

A

ss

20
Q

In what sense does a method never return an array?

A

ss

21
Q

What is the return type of the round() method?

A

ss

22
Q

How do we use Scanner to read every line of a file?

A

ss

23
Q

What is the difference between format() and System.out.printf()?

A

ss

24
Q

What does the split() method do?

A

ss

25
Q

What happens if the item matching “%s” is not a string?

A

ss

26
Q

What is the output by the following?

System.out.printf(“From %s to %s is %1.2f miles.%n”, “here”, “eternity”, 1.0/0);

A

ss

27
Q

When talking about System.out.printf(), then what is the difference between right and left justification, and how do we obtain each one?

A

ss

28
Q

When should we use a for-each loop? In particular, what can it not do?

A

ss

29
Q

What are enum types used for?

A

ss

30
Q

How do we use an enum type defined in another class?

A

ss

31
Q

How do we write the type of an array which has a String base type?

A

ss

32
Q

What benefits does class constants and a set if its choices have, compared with using the integer values directly?

A

ss

33
Q

What are the dangers of class constant and a set of its choices approach?

A

ss

34
Q

In what sense does an array type variable never contain and array?

A

ss