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
AP GOV Unit 5
Updated 915d ago
0.0(0)
note
Unit 3 Full Guide
Updated 320d ago
0.0(0)
note
Microbiology Unit 2 Review
Updated 510d ago
0.0(0)
note
Latest Face
Updated 1202d ago
0.0(0)
note
APUSH Period 1 (1491-1607)
Updated 1046d ago
0.0(0)
note
AP GOV Unit 5
Updated 915d ago
0.0(0)
note
Unit 3 Full Guide
Updated 320d ago
0.0(0)
note
Microbiology Unit 2 Review
Updated 510d ago
0.0(0)
note
Latest Face
Updated 1202d ago
0.0(0)
note
APUSH Period 1 (1491-1607)
Updated 1046d ago
0.0(0)

Explore top flashcards

flashcards
Unidad 1- 2025
32
Updated 550d ago
0.0(0)
flashcards
Poetry Vocab
20
Updated 1115d ago
0.0(0)
flashcards
Sport, Spiel, und Spaß
60
Updated 188d ago
0.0(0)
flashcards
Biology Practice Exam
40
Updated 1053d ago
0.0(0)
flashcards
Henry M. Flagler Quiz Review
41
Updated 793d ago
0.0(0)
flashcards
HN&F exam 4
32
Updated 1215d ago
0.0(0)
flashcards
(16) reproductive system
71
Updated 1209d ago
0.0(0)
flashcards
Unidad 1- 2025
32
Updated 550d ago
0.0(0)
flashcards
Poetry Vocab
20
Updated 1115d ago
0.0(0)
flashcards
Sport, Spiel, und Spaß
60
Updated 188d ago
0.0(0)
flashcards
Biology Practice Exam
40
Updated 1053d ago
0.0(0)
flashcards
Henry M. Flagler Quiz Review
41
Updated 793d ago
0.0(0)
flashcards
HN&F exam 4
32
Updated 1215d ago
0.0(0)
flashcards
(16) reproductive system
71
Updated 1209d ago
0.0(0)