Data Structures: Arrays and Array Processing
18 Questions
1 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is the correct syntax to declare and create a one-dimensional array of integers?

  • int[] arr = new int;
  • int arr = new int[15];
  • int arr = new int[15];
  • int[] arr; arr = new int[15]; (correct)

What can be the type of elements in an array?

  • Neither primitives nor objects
  • Only objects
  • Either primitives or objects (correct)
  • Only primitives

What is the term for the variables in an array?

  • Components (correct)
  • Variables
  • Items
  • Elements

What happens when you create a new array?

<p>Only the array is created, not the objects that will be stored in it (A)</p> Signup and view all the answers

How do you create an array of Strings and store 5 Strings in it?

<p>String[] str = new String[5]; (B)</p> Signup and view all the answers

What is the term for the number of components an array has?

<p>Length (A)</p> Signup and view all the answers

What is the type of data stored in an array?

<p>Same data type (B)</p> Signup and view all the answers

What is the syntax to refer to an array element?

<p>arrayname[subscript] (D)</p> Signup and view all the answers

What happens when an array is passed as a parameter to a function?

<p>A reference to the array is passed (D)</p> Signup and view all the answers

How are arrays instantiated in a program?

<p>Using the new operator (A)</p> Signup and view all the answers

What is the index of the last element in an array with 15 elements?

<p>14 (B)</p> Signup and view all the answers

What is the result of arr[k % j] if k is 7 and j is 5?

<p>arr[2] (D)</p> Signup and view all the answers

What is the purpose of the 'length' variable in an array?

<p>To get the number of elements in an array (D)</p> Signup and view all the answers

What happens when you initialize an array without assigning initial values?

<p>It is initialized with default values (A)</p> Signup and view all the answers

What is the syntax to initialize an array with initial values in Java?

<p>int[] arr = new int[] {-2,8,-1,-3,16,20,25,16,16,8,18,19,45,21,-2}; (D)</p> Signup and view all the answers

How do you refer to the elements of an array?

<p>Using the array name followed by the index (B)</p> Signup and view all the answers

What is the default value of an uninitialized integer array in Java?

<p>0 (B)</p> Signup and view all the answers

How do you declare an array of objects in Java?

<p>Person[] persons; (B)</p> Signup and view all the answers

More Like This

Array Data Structures Quiz
10 questions
Array Data Structures Quiz
5 questions
Data Structures: Array Concepts
0 questions
Use Quizgecko on...
Browser
Browser