module 6 zybook 7.2 Arrays Array declarations and accessing elements

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/32

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 7:39 PM on 3/17/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

33 Terms

1
New cards

What is an array?

A) A random list of items

B) An ordered list of items of a given data type

C) A data structure for storing different data types

D) A collection of elements with no specific order

B) An ordered list of items of a given data type

2
New cards

What is an element in the context of an array?

A) An ordered item in the array

B) An unordered item in the array

C) A data type used to define the array

D) A variable used to access the array

A) An ordered item in the array

3
New cards

Why do programmers use arrays?

A) To maintain lists of items

B) To store data of different data types

C) To organize complex data structures

D) To perform mathematical calculations

A) To maintain lists of items

4
New cards

What is the purpose of an array declaration?

A) To define the size and data type of the array

B) To access the elements of the array

C) To iterate through the array

D) To modify the elements of the array

A) To define the size and data type of the array

5
New cards

What is the purpose of array declarations in programming?

A) To specify the data type of the array

B) To provide a name for the array

C) To determine the number of elements the array can hold

D) All of the above

D) All of the above

6
New cards

How do you access individual elements of an array?

A) By using the array's name followed by the index in square brackets

B) By using the array's name followed by parentheses

C) By using the array's name followed by curly braces

D) By using the array's name followed by a dot operator

A) By using the array's name followed by the index in square brackets

7
New cards

What symbols are used in array declaration to indicate that the variable is an array reference?

A) ( )

B) [ ]

C) { }

D) < >

B) [ ]

8
New cards

What does the `new` keyword do in array creation?

A) Assigns a value to an array element

B) Allocates memory for the array

C) Specifies the data type of the array

D) Determines the size of the array

B) Allocates memory for the array

9
New cards

In the example `int[] gameScores = new int[4];`, what does `gameScores` refer to?

A) The data type of the array

B) The number of elements in the array

C) The allocated array of four integers

D) The index of the first array element

C) The allocated array of four integers

10
New cards

allocate

to distribute

11
New cards

What is the index of the first element in an array?

A) 0

B) 1

C) -1

D) The size of the array

A) 0

12
New cards

What are [ ] symbols called in the context of arrays?

A) Parentheses

B) Brackets

C) Braces

D) Quotes

B) Brackets

13
New cards

What are { } symbols called in the context of arrays?

A) Parentheses

B) Brackets

C) Braces

D) Quotes

C) Braces

14
New cards

What is the term for the number inside the brackets in an array access?

A) Identifier

B) Element

C) Index

D) Variable

C) Index

15
New cards

When does assigning an allocated array to reference variable occur?

A) During the declaration of the array reference variable

B) After the declaration of the array reference variable

C) It is not possible to assign an allocated array to the array reference variable

D) The assignment occurs automatically when an array is created

B) can be After the declaration of the array reference variable

16
New cards

Can a programmer declare an array reference variable without allocating the array?

Yes.

17
New cards

int[] yearsArr = new int[4];

yearsArr[0] = 1999;

yearsArr [1] = 2012;

yearsArr [2] = 2025;

1) How many elements in memory does the array declaration create?

4

<p>4</p>
18
New cards

Recall that the array declaration was int [] yearsArr = new

int [4];. Is currYear = yearsArr [4] a valid assignment?

•Yes, it accesses the fourth element.

No, yearsArr|4] does not exist.

No, yearsArr|4] does not exist.

The valid indices start at 0, so the four elements are 0, 1, 2, and 3. Accessing yearsArr[4] will cause an error.

19
New cards

What is the proper way to access the first element in array yearsArr?

yearsArr[1]

yearsArr[0]

yearsArr[0]

20
New cards

What is the index of the last element for the following array: int[] pricesArr = new int[100];

99

100

101

99

The 100 elements will have indices 0..99.

21
New cards

Declare and initialize an array named myVals that stores 10 elements of type int with default values.

Assign variable x with the value stored at index 8 of array myVals.

Assign the second element of array myVals with the value 555

int[] myVals = new int[10];

x = myVals[8];

myVals[1] = 555;

22
New cards

Assign myVals array element at the index held in currIndex with the value 777.

myVals[currIndex] = 777;

23
New cards

Assign tempVal with the myVals array element at the index one after the value held in variable i

24
New cards

Assign tempVal with the myVals array element at the index one after the value held in variable i.

tempVal = myVals[i + 1];

25
New cards

What happens to an array's elements when it is initialized using the new keyword?

A) They are set to default values specified by the programmer

B) They remain uninitialized and contain random values

C) They are initialized to default values based on their data types

D) The new keyword cannot be used to initialize arrays

C) They are initialized to default values based on their data types

26
New cards

What is the default value for elements of integer and floating-point data types in Java?

A) 0

B) 1

C) true

D) false

A) 0

27
New cards

How can a programmer initialize an array's elements with non-default values?

A) By using the new keyword followed by specific values in parentheses

B) By specifying the initial values in braces {} separated by commas

C) By declaring the array without any values and then using a loop to assign them

D) By using the set method provided by the array class

B) By specifying the initial values in braces {} separated by commas

28
New cards

In the example int[] myArray = {5, 7, 11};, how many elements are there in the array?

A) 1

B) 2

C) 3

D) 4

C) 3

29
New cards

What is array initialization in programming?

A) The process of creating an array using the `new` keyword

B) The process of setting the initial values of an array's elements

C) The process of defining the data type of an array

D) The process of accessing array elements through loops

: B) The process of setting the initial values of an array's elements

30
New cards

What are the default values assigned to elements of integer and floating-point data types during array initialization?

A) 0 for integer and floating-point, and false for boolean

B) 1 for integer and floating-point, and true for boolean

C) false for integer and floating-point, and 0 for boolean

D) 0 for integer and floating-point, and true for boolean

A) 0 for integer and floating-point, and false for boolean

31
New cards

How can a programmer initialize an array with specific initial values without using the `new` keyword?

A) By specifying the initial values in braces {} separated by commas

B) By using the `new` keyword followed by specific values in parentheses

C) By defining the data type of the array and then populating it with a loop

D) By using the `set` method provided by the array class

A) By specifying the initial values in braces {} separated by commas

32
New cards

What does the following array initialization represent in Java?

int[] numbers = {2, 4, 6, 8, 10};

A) An array of 5 integers initialized with the values 2, 4, 6, 8, and 10

B) An array of 5 integers initialized with default values

C) An array of 5 integers with no initial values

D) An empty array with no elements

A) An array of 5 integers initialized with the values 2, 4, 6, 8, and 10

33
New cards

What does the term "default value" refer to in programming?

A) The value assigned to a variable after it has been modified

B) The value assigned to a variable when it is created or declared without an explicit value

C) The value that a variable must have before it can be used in a program

D) The value assigned to a variable to mark it as empty or uninitialized

B) The value assigned to a variable when it is created or declared without an explicit value

Explore top notes

note
Chapter 9: Chemical Equilibrium
Updated 1095d ago
0.0(0)
note
Wedding Wind
Updated 1257d ago
0.0(0)
note
College Prep Chemistry, Elements
Updated 1281d ago
0.0(0)
note
Grade 10 Biology: Lesson 9
Updated 1181d ago
0.0(0)
note
Chapter 9: Chemical Equilibrium
Updated 1095d ago
0.0(0)
note
Wedding Wind
Updated 1257d ago
0.0(0)
note
College Prep Chemistry, Elements
Updated 1281d ago
0.0(0)
note
Grade 10 Biology: Lesson 9
Updated 1181d ago
0.0(0)

Explore top flashcards

flashcards
Odyssey Test review
85
Updated 535d ago
0.0(0)
flashcards
duits kapitel 2 woordenschat
101
Updated 878d ago
0.0(0)
flashcards
US State Capitals
50
Updated 937d ago
0.0(0)
flashcards
APUSH 23-25 Simple IDs
90
Updated 60d ago
0.0(0)
flashcards
French Indefinite Articles
34
Updated 705d ago
0.0(0)
flashcards
AP Psych Unit 3
79
Updated 861d ago
0.0(0)
flashcards
Waves key words and definitions
21
Updated 476d ago
0.0(0)
flashcards
Map of East Asia- Physical map
34
Updated 428d ago
0.0(0)
flashcards
Odyssey Test review
85
Updated 535d ago
0.0(0)
flashcards
duits kapitel 2 woordenschat
101
Updated 878d ago
0.0(0)
flashcards
US State Capitals
50
Updated 937d ago
0.0(0)
flashcards
APUSH 23-25 Simple IDs
90
Updated 60d ago
0.0(0)
flashcards
French Indefinite Articles
34
Updated 705d ago
0.0(0)
flashcards
AP Psych Unit 3
79
Updated 861d ago
0.0(0)
flashcards
Waves key words and definitions
21
Updated 476d ago
0.0(0)
flashcards
Map of East Asia- Physical map
34
Updated 428d ago
0.0(0)