14. Arrays Flashcards
Does an array object have a variable or a fixed size?
ss
Do we need to change the program source code in order to change the size of an array used by a program?
ss
Which of the following variable declarations are legal?
- int {} smallPrimes = {2, 3, 5, 7, 11, 13, 17, 19};
- int [] smallPrimes = [2, 3, 5, 7, 11, 13, 17, 19];
- int [] smallPrimes = {2, 3, 5, 7, 11, 13, 17, 19};
- int {} smallPrimes = [2, 3, 5, 7, 11, 13, 17, 19];
ss
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];
ss
How many references are involved in the following?
int[][] my2DArray = new int[5][4]
20
What set of indices does an array of ten elements have?
ss
Consider the following.
int[][] my2DArray = new int[5][4];
Which element is acces by my2DArray[4][1]?
- The first element in the last row.
- The second element in the last row.
- The first element in the penultimate row.
- The fourth element in the first row.
- The third element in the first row.
ss
How do we find the length of an array?
ss
What is the difference between and array variable containing null, and one containing a reference to an empty array?
ss
What does an ‘array of objects’ contain?
ss
What other variable do we need to support a partially filled array?
ss
What is the minimum size increase when extending an array? What is a good size increase?
ss
What is the difference between shallow and deep copies?
ss
How does linear search in a list work?
ss
Give three examples of a sort order on simple data, such as numbers or names.
ss
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?
ss
What is the essential difference between double division by zero and that of integer division?
ss
Which of the following expressions could produce an exception, where size and sum are int variables?
- size == 0 || sum / size >= 0
- sum / size < 10 && size != 0
ss
What is the most obvious example of accepting parameters of an array type?
ss
In what sense does a method never return an array?
ss
What is the return type of the round() method?
ss
How do we use Scanner to read every line of a file?
ss
What is the difference between format() and System.out.printf()?
ss
What does the split() method do?
ss
What happens if the item matching “%s” is not a string?
ss
What is the output by the following?
System.out.printf(“From %s to %s is %1.2f miles.%n”, “here”, “eternity”, 1.0/0);
ss
When talking about System.out.printf(), then what is the difference between right and left justification, and how do we obtain each one?
ss
When should we use a for-each loop? In particular, what can it not do?
ss
What are enum types used for?
ss
How do we use an enum type defined in another class?
ss
How do we write the type of an array which has a String base type?
ss
What benefits does class constants and a set if its choices have, compared with using the integer values directly?
ss
What are the dangers of class constant and a set of its choices approach?
ss
In what sense does an array type variable never contain and array?
ss