Podcast
Questions and Answers
Which of the following is the correct way to create an array with 20 double
elements?
Which of the following is the correct way to create an array with 20 double elements?
Given the declaration below, what is the value of array[3]?
int[] array = {4, 3, 5, 2, 0};
Given the declaration below, what is the value of array[3]? int[] array = {4, 3, 5, 2, 0};
Given the declaration below, which of the following statements would cause a run- time error?
int[] array = {4, 3, 5, 2, 0};
Given the declaration below, which of the following statements would cause a run- time error?
int[] array = {4, 3, 5, 2, 0};
What output is generated by the code segment below?
int[] values = new int[10];
for (int k = 0; k < values.length; k++)
{
values[k] = k * 2;
}
System.out.println(values[5]);
What output is generated by the code segment below?
int[] values = new int[10]; for (int k = 0; k < values.length; k++) { values[k] = k * 2; } System.out.println(values[5]);
Signup and view all the answers
Insert the missing statement in the following code fragment, which is designed to initialize the array elements with the values 1, 2, 3, . . . , 100.
int[] numbers = new int[100];
for (int k = 0; k < numbers.length; k++)
{
}
Insert the missing statement in the following code fragment, which is designed to initialize the array elements with the values 1, 2, 3, . . . , 100.
int[] numbers = new int[100]; for (int k = 0; k < numbers.length; k++) {
}
Signup and view all the answers
What output is generated by the code fragment below?
int[] values = { 1, 3, 1, 3, 1 }; int[] numbers = values;
for (int k = 0; k < values.length; k++)
{
values[k] = k * 2;
}
System.out.print(values[2]); System.out.print(" " + numbers[2]);
What output is generated by the code fragment below?
int[] values = { 1, 3, 1, 3, 1 }; int[] numbers = values; for (int k = 0; k < values.length; k++) { values[k] = k * 2; } System.out.print(values[2]); System.out.print(" " + numbers[2]);
Signup and view all the answers
What output is generated by the program segment below?
int[] values = { 1, 3, 5, 3, 7 }; int count = 0;
for (int number : values)
{
if (number > 4)
{
count++;
}
}
System.out.print(count);
What output is generated by the program segment below?
int[] values = { 1, 3, 5, 3, 7 }; int count = 0; for (int number : values) { if (number > 4) { count++; }
} System.out.print(count);
Signup and view all the answers
Complete the code fragment below by inserting the statement that makes the most appropriate use of the enhanced for loop.
int[] values = { 1, 3, 5, 3, 7 }; for (int number : values)
{
}
Complete the code fragment below by inserting the statement that makes the most appropriate use of the enhanced for loop.
int[] values = { 1, 3, 5, 3, 7 }; for (int number : values) {
}
Signup and view all the answers