quiz image

Creating an Array with 20 Double Elements Quiz

RiskFreeAustin avatar
RiskFreeAustin
·
·
Download

Start Quiz

Study Flashcards

8 Questions

Which of the following is the correct way to create an array with 20 double elements?

double[] array = new double[20];

Given the declaration below, what is the value of array[3]? int[] array = {4, 3, 5, 2, 0};

2

Given the declaration below, which of the following statements would cause a run- time error?

int[] array = {4, 3, 5, 2, 0};

a. array[5] = 1;

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]);

10

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++) {

}

a. numbers[k] = k + 1;

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]);

4 4

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);

2

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) {

}

d. System.out.println(number);

Test your knowledge on creating arrays with double elements by selecting the correct way to create an array with 20 double elements. Choose the right syntax and enhance your understanding of array creation in programming.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free
Use Quizgecko on...
Browser
Browser