On Making Arrays

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

1/19

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 4:39 AM on 12/10/24
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

20 Terms

1
New cards

How do you create a 1D array?

int[] array = new int[5];

2
New cards

How do you create a 2D array?

int[][] matrix = new int[3][4];

3
New cards

What is the default value of array elements?

0 for numeric arrays, null for objects.

4
New cards

How do you initialize a 1D array with values?

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

5
New cards

How do you initialize a 2D array with values?

int[][] matrix = {{1, 2, 3}, {4, 5, 6}};

6
New cards

How do you fill a 1D array with user input?

for (int i = 0; i < array.length; i++) { array[i] = scanner.nextInt(); }

7
New cards

How do you fill a 2D array with user input?

for (int i = 0; i < matrix.length; i++) { for (int j = 0; j < matrix[i].length; j++) { matrix[i][j] = scanner.nextInt(); }}

8
New cards

How do you iterate through a 1D array to display elements?

for (int i = 0; i < array.length; i++) { System.out.println(array[i]); }

9
New cards

How do you iterate through a 2D array to display elements?

for (int i = 0; i < matrix.length; i++) { for (int j = 0; j < matrix[i].length; j++) { System.out.print(matrix[i][j] + " "); } System.out.println(); }

10
New cards

How do you sum all elements in a 1D array?

int sum = 0; for (int num : array) { sum += num; }

11
New cards

How do you sum all elements in a 2D array?

int sum = 0; for (int i = 0; i < matrix.length; i++) { for (int j = 0; j < matrix[i].length; j++) { sum += matrix[i][j]; }}

12
New cards

How do you get the length of a 1D array?

array.length

13
New cards

How do you get the number of rows in a 2D array?

matrix.length

14
New cards

How do you get the number of columns in a 2D array?

matrix[i].length (for row i).

15
New cards

What is the index range for an array of size 5?

0 to 4.

16
New cards

How do nested loops work for a 2D array?

Outer loop = rows, Inner loop = columns.

17
New cards

What is the default value for uninitialized elements in an array?

0 for numbers, false for booleans, null for objects.

18
New cards

Can arrays hold objects in Java?

Yes.

19
New cards

.length in arrays represents what?

The total number of elements.

20
New cards

What is a ragged array?

A 2D array where rows have different lengths.

Explore top notes

note
Photosynthesis Quiz
Updated 1282d ago
0.0(0)
note
Unit 5: Period 5: 1844-1877
Updated 1063d ago
0.0(0)
note
Dutch
Updated 410d ago
0.0(0)
note
Iteration
Updated 1094d ago
0.0(0)
note
Specific Phobias
Updated 1161d ago
0.0(0)
note
Photosynthesis Quiz
Updated 1282d ago
0.0(0)
note
Unit 5: Period 5: 1844-1877
Updated 1063d ago
0.0(0)
note
Dutch
Updated 410d ago
0.0(0)
note
Iteration
Updated 1094d ago
0.0(0)
note
Specific Phobias
Updated 1161d ago
0.0(0)

Explore top flashcards

flashcards
Unit 2 Health ILSW 7
149
Updated 277d ago
0.0(0)
flashcards
Religion 2 - Kristendom
53
Updated 1146d ago
0.0(0)
flashcards
La Siesta del Martes
55
Updated 928d ago
0.0(0)
flashcards
Piliavin
59
Updated 1105d ago
0.0(0)
flashcards
9
106
Updated 1138d ago
0.0(0)
flashcards
Structures with Hammy
92
Updated 1072d ago
0.0(0)
flashcards
Unit 2 Health ILSW 7
149
Updated 277d ago
0.0(0)
flashcards
Religion 2 - Kristendom
53
Updated 1146d ago
0.0(0)
flashcards
La Siesta del Martes
55
Updated 928d ago
0.0(0)
flashcards
Piliavin
59
Updated 1105d ago
0.0(0)
flashcards
9
106
Updated 1138d ago
0.0(0)
flashcards
Structures with Hammy
92
Updated 1072d ago
0.0(0)