On Making Arrays

studied byStudied by 0 people
0.0(0)
learn
LearnA personalized and smart learning plan
exam
Practice TestTake a test on your terms and definitions
spaced repetition
Spaced RepetitionScientifically backed study method
heart puzzle
Matching GameHow quick can you match all your cards?
flashcards
FlashcardsStudy terms and definitions

1 / 19

encourage image

There's no tags or description

Looks like no one added any tags here yet for you.

20 Terms

1

How do you create a 1D array?

int[] array = new int[5];

New cards
2

How do you create a 2D array?

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

New cards
3

What is the default value of array elements?

0 for numeric arrays, null for objects.

New cards
4

How do you initialize a 1D array with values?

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

New cards
5

How do you initialize a 2D array with values?

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

New cards
6

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

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

New cards
7

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(); }}

New cards
8

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

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

New cards
9

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(); }

New cards
10

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

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

New cards
11

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]; }}

New cards
12

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

array.length

New cards
13

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

matrix.length

New cards
14

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

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

New cards
15

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

0 to 4.

New cards
16

How do nested loops work for a 2D array?

Outer loop = rows, Inner loop = columns.

New cards
17

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

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

New cards
18

Can arrays hold objects in Java?

Yes.

New cards
19

.length in arrays represents what?

The total number of elements.

New cards
20

What is a ragged array?

A 2D array where rows have different lengths.

New cards

Explore top notes

note Note
studied byStudied by 12 people
656 days ago
5.0(1)
note Note
studied byStudied by 50 people
102 days ago
5.0(1)
note Note
studied byStudied by 35 people
890 days ago
5.0(3)
note Note
studied byStudied by 71 people
656 days ago
5.0(1)
note Note
studied byStudied by 5 people
731 days ago
5.0(1)
note Note
studied byStudied by 5 people
834 days ago
5.0(1)
note Note
studied byStudied by 47 people
864 days ago
5.0(1)
note Note
studied byStudied by 5703 people
657 days ago
4.8(18)

Explore top flashcards

flashcards Flashcard (47)
studied byStudied by 3 people
66 days ago
5.0(1)
flashcards Flashcard (23)
studied byStudied by 4 people
60 days ago
4.0(1)
flashcards Flashcard (278)
studied byStudied by 39 people
113 days ago
5.0(1)
flashcards Flashcard (20)
studied byStudied by 59 people
315 days ago
5.0(2)
flashcards Flashcard (29)
studied byStudied by 40 people
447 days ago
5.0(1)
flashcards Flashcard (174)
studied byStudied by 1 person
36 days ago
5.0(1)
flashcards Flashcard (32)
studied byStudied by 2 people
324 days ago
5.0(1)
flashcards Flashcard (64)
studied byStudied by 3614 people
659 days ago
4.9(48)
robot