CS 1331 Exam 1 with accurate detailed|!! |!! |!! |!! |!! |!! |!!
solutions
Array - correct answer✔✔Linear, homogenous set of data where you can
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
access each element by an increasing index starting at 0
|!! |!! |!! |!! |!! |!! |!! |!! |!!
What does it mean when we say an array is "homogenous"? - correct
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
answer✔✔The array is of a specific type set upon its declaration, i.e. you |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
can't put doubles in a String[] array
|!! |!! |!! |!! |!! |!!
How would you declare an array of integers named "a"? (no specified
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
length or contents) - correct answer✔✔int[] a;
|!! |!! |!! |!! |!! |!!
How would you declare an array of length 10 with integers inside named
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
"a"? - correct answer✔✔int[] a = new int[10]
|!! |!! |!! |!! |!! |!! |!!
What two ways could you declare an array of integers 1-10 increasing by
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
1 named "a"? - correct answer✔✔1) int[] a = {1,2,3,4,5,6,7,8,9,10}
|!! |!! |!! |!! |!! |!! |!! |!! |!!
or with a for loop
|!! |!! |!! |!!
If you declare an array as "int[] a;", what do you have to re-do when you
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
instantiate it? - correct answer✔✔Restate the type: |!! |!! |!! |!! |!! |!!
"a = new int[] {2,4,6}"
|!! |!! |!! |!!
How would you access the 1st element of array "a"? - correct
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
answer✔✔a[0];
How do you access the length of array "a"? - correct answer✔✔a.length
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
, Is accessing the length of an array a method? Why or why not? - correct
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
answer✔✔No! It's a public int part of the array class, hence NO |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
parenthesis
What is an array? - correct answer✔✔An object
|!! |!! |!! |!! |!! |!! |!!
For array "a" is a[a.length] a valid way to access an element? - correct
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
answer✔✔No! The max index == (a.length - 1) |!! |!! |!! |!! |!! |!! |!!
When you see a problem with an array, what should you use? - correct
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
answer✔✔A for loop |!! |!!
What does it mean when we say an array is static? - correct answer✔✔You
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
can't resize them! You would have to make a new array of bigger size &
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
copy everything. |!!
What is the syntax for a while loop? - correct answer✔✔while
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
(someCondition) { |!!
|!! //things that can change someCondition
|!! |!! |!! |!!
}
What is the most common mistake when implementing while loops? -
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
correct answer✔✔Creating an infinite loop
|!! |!! |!! |!!
What is the syntax for a do while loop? - correct answer✔✔do {
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
} while (someCondition);
|!! |!!
solutions
Array - correct answer✔✔Linear, homogenous set of data where you can
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
access each element by an increasing index starting at 0
|!! |!! |!! |!! |!! |!! |!! |!! |!!
What does it mean when we say an array is "homogenous"? - correct
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
answer✔✔The array is of a specific type set upon its declaration, i.e. you |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
can't put doubles in a String[] array
|!! |!! |!! |!! |!! |!!
How would you declare an array of integers named "a"? (no specified
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
length or contents) - correct answer✔✔int[] a;
|!! |!! |!! |!! |!! |!!
How would you declare an array of length 10 with integers inside named
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
"a"? - correct answer✔✔int[] a = new int[10]
|!! |!! |!! |!! |!! |!! |!!
What two ways could you declare an array of integers 1-10 increasing by
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
1 named "a"? - correct answer✔✔1) int[] a = {1,2,3,4,5,6,7,8,9,10}
|!! |!! |!! |!! |!! |!! |!! |!! |!!
or with a for loop
|!! |!! |!! |!!
If you declare an array as "int[] a;", what do you have to re-do when you
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
instantiate it? - correct answer✔✔Restate the type: |!! |!! |!! |!! |!! |!!
"a = new int[] {2,4,6}"
|!! |!! |!! |!!
How would you access the 1st element of array "a"? - correct
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
answer✔✔a[0];
How do you access the length of array "a"? - correct answer✔✔a.length
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
, Is accessing the length of an array a method? Why or why not? - correct
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
answer✔✔No! It's a public int part of the array class, hence NO |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
parenthesis
What is an array? - correct answer✔✔An object
|!! |!! |!! |!! |!! |!! |!!
For array "a" is a[a.length] a valid way to access an element? - correct
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
answer✔✔No! The max index == (a.length - 1) |!! |!! |!! |!! |!! |!! |!!
When you see a problem with an array, what should you use? - correct
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
answer✔✔A for loop |!! |!!
What does it mean when we say an array is static? - correct answer✔✔You
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
can't resize them! You would have to make a new array of bigger size &
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
copy everything. |!!
What is the syntax for a while loop? - correct answer✔✔while
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
(someCondition) { |!!
|!! //things that can change someCondition
|!! |!! |!! |!!
}
What is the most common mistake when implementing while loops? -
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
correct answer✔✔Creating an infinite loop
|!! |!! |!! |!!
What is the syntax for a do while loop? - correct answer✔✔do {
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
} while (someCondition);
|!! |!!