Question: 1
Which of the following arrays has a length of 5?
double[] arr = new double[6];
double[] arr = {0, 1, 2, 3, 4, 5};
double[] arr = new double[]{1, 2.3, 4, 5};
All of these
None of these
None of These
Which of the following are valid arrays?
I. int[] coolArray = {1, 2, 3};
II. int[] threeThings = {1.0, 2.0, 3.0};
III. int[] = {“1”, “2”, “3”};
I only
II only
III only
I and II
I and III
I only
What is the output of the following program?
hel
hello
hellow
Error
h e l l o w
Error
You are working at the frozen yogurt shop in the mall. Your boss asks you to count how many flavors have the word chocolate in their name. You begin going through the list of flavors, but quickly realize that their are over 9000 flavors to check! Luckily, your boss stored all of the different flavors in a Java Array named flavorArray on the company computer. Write a Java program to count the number of flavors that have chocolate in their name.
int chocolateFlavorCount = 0;
for(int i = 0; i < flavorArray.length; i++)
{
flavorArray[i].contains(“chocolate”);
}
System.out.println(chocolateFlavorCount);
int chocolateFlavorCount = 0;
for(int i = 0; i < flavorArray.length; i++)
{
if(flavorArray[i].contains(“chocolate”))
{
chocolateFlavorCount++;
}
}
System.out.println(chocolateFlavorCount);
int chocolateFlavorCount = 0;
for(int i = 0; i < flavorArray.length; i++)
{
if(flavorArray[i].contains(“chocolate”))
{
chocolateFlavorCount++;
}
}
System.out.println(chocolateFlavorCount);
What value will be held in mysteryNumber when this code finishes running?
0
17
1
16
17
What will the Array gameBoard contain after this code runs?
Consider the following code snippet:
int[] arr = {1, 2, 3, 4, 5};
int[] copy = arr;
copy[4] = 2;
After this code runs, what is the value of arr[4]?
5
4
2
The code will error.
2
Consider the following method that processes an array to find the smallest value in the array. The array has a nonzero length and is initialized with int values.
Which replacement(s) for /* some value */ will always result in correct execution of findMin?
I. Integer.MAX_VALUE
II.Integer.MIN_VALUE
III. arr[0]
I only
II only
III only
I and III only
II and III only
I and III only
Given the following values of arr and the mystery method, what will the values of arr be after you execute: mystery()?
Which of the following statements is valid? Assume that variable arr is an array of n integers and that the following is true:
arr[0] != arr[i] for all values from 1 through n - 1
Given the following array:
String[] languages = {“Java”, “JavaScript”, “Python”, “C++”};
Which of the following will produce an ArrayIndexOutOfBoundsException?
for (int i = 1; i <= languages.length; i++)
{
System.out.println(languages[i-1]);
}
for (int i = 0; i < languages.length; i++)
{
System.out.println(languages[i]);
}
for (int i = 0; i < languages.length; i++)
{
System.out.println(languages[i-1]);
}
for (int i = 0; i < languages.length; i++)
{
System.out.println(languages[i-1]);
}
The following codes are intended to add 5 to each item in the array.
I.
int[] numbers = {1, 2, 3, 4};
for (int i = 0; i < numbers.length; i++)
{
numbers[i] += 5;
}
II.
int[] numbers = {1, 2, 3, 4};
for (int number : numbers)
{
number += 5;
}
Which statement is true?
The following code is designed to return true if a target value is present in an array of integers.
public boolean search(int[] arr, int target)
{
for (int number : arr)
{
if (number != target)
{
return false;
} } return true;
}
Which of the following statements is true?
What does the following code do when executed?
The following code is intended to shift all elements to the right by one space and wrap the last element around to the first element.
Which statement is true?

The following method is intended to return true if the array element value contains the same number in consecutive array elements.
Which of the following are needed to correct the code?
I. Change line 3 to: int i = 0;
II. Change line 4 to: while (i < nums.length - 1)
III. Swap lines 7 and 10
I only
II only
III only
Make both I and II changes

Make both I and II changes
Which of the following loops will NOT print every element in an integer array?
(1)
for (int i = 1; i < array.length; i++) {
System.out.println(array[i-1]);
}
(2)
for (int i = 1; i <= array.length; i++) {
System.out.println(array[i-1]);
}
(3)
int i = 1; while (i <= array.length) {
System.out.println(array[i-1]); i++;
}
(1)
for (int i = 1; i < array.length; i++) {
System.out.println(array[i-1]);
}
Which of the following will initialize a boolean array of three elements all containing true?

I only
II only
III only
I and III only
I, II, and III
I and III only
What will print out when the following code executes?
0
1
2
3
4
5

2
Given the array:
String[] fruit = {“Apple”, “Pear”, “Pineapple”, “Carrot”, “Banana”, “Lettuce”};
Which code will correctly replace Carrot and Lettuce in the array?
Define Array:
Array: An object that can store many values of the same type in a single variable
array.length
Returns the length of the array
array[index]
Accesses an element in the array to either update or retrieve it