Creating an Array with 20 Double Elements Quiz

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Listen to an AI-generated conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

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

  • double[] array = new double[20]; (correct)
  • double array = new double[20];
  • c. double[20] array = new double[];
  • d. double[] array = new array[20];

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

  • 5
  • 2 (correct)
  • 0
  • 3

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; (correct)
  • b. array[2] = array[3];
  • c. array[0] = 1;
  • d. array[4] = 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]);

<p>10 (D)</p>
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++) {

}

<p>a. numbers[k] = k + 1; (C)</p>
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]);

<p>4 4 (D)</p>
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);

<p>2 (C)</p>
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) {

}

<p>d. System.out.println(number); (D)</p>
Signup and view all the answers

Flashcards are hidden until you start studying

More Like This

Arrays in Computer Programming 2
12 questions
Arrays and Pointers in C
10 questions

Arrays and Pointers in C

OutstandingAntigorite3279 avatar
OutstandingAntigorite3279
Use Quizgecko on...
Browser
Browser